Skip to content

Commit

Permalink
chore(docs): cleanup workos provider page copy
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed Apr 28, 2024
1 parent 2028eae commit 4ae4929
Showing 1 changed file with 4 additions and 69 deletions.
73 changes: 4 additions & 69 deletions docs/pages/getting-started/providers/workos.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
title: WorkOS
---

import { Callout } from "nextra/components"
import { Code } from "@/components/Code"

Expand Down Expand Up @@ -81,72 +85,3 @@ app.use(
</Code.Express>
</Code>

### Notes

WorkOS is not an identity provider itself, but, rather, a bridge to multiple single sign-on (SSO) providers.
As a result, we need to make some additional changes to authenticate users using WorkOS.

In order to sign a user in using WorkOS, we need to specify which WorkOS Connection to use.
A common way to do this is to collect the user's email address and extract the domain. This can be done using a custom login page.
To add a custom login page, you can use the `pages` option:

```js filename="pages/api/auth/[...nextauth].js"
pages: {
signIn: "/auth/signin",
}
```

We can then add a custom login page that displays an input where the user can enter their email address.
We then extract the domain from the user's email address and pass it to the `authorizationParams` parameter on the `signIn` function:

```js filename="pages/auth/signin.js"
import { useState } from "react"
import { getProviders, signIn } from "next-auth/react"

export default function SignIn({ providers }) {
const [email, setEmail] = useState("")

return (
<>
{Object.values(providers).map((provider) => {
if (provider.id === "workos") {
return (
<div key={provider.id}>
<input
type="email"
value={email}
placeholder="Email"
onChange={(event) => setEmail(event.target.value)}
/>
<button
onClick={() =>
signIn(provider.id, undefined, {
domain: email.split("@")[1],
})
}
>
Sign in with SSO
</button>
</div>
)
}

return (
<div key={provider.id}>
<button onClick={() => signIn(provider.id)}>
Sign in with {provider.name}
</button>
</div>
)
})}
</>
)
}

export async function getServerSideProps(context) {
const providers = await getProviders()
return {
props: { providers },
}
}
```

0 comments on commit 4ae4929

Please sign in to comment.