Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: next auth v5 #760

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions docs/quick-starts/framework/next-auth/_config-provider.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import TabItem from '@theme/TabItem';
import Tabs from '@theme/Tabs';

import redirectUriFigure from '../../assets/next-auth-redirect-uri.png';
import ConfigureRedirectUri from '../../fragments/_configure-redirect-uri.mdx';
import GetAppSecret from '../../fragments/_get-app-secret.mdx';
Expand All @@ -23,6 +26,49 @@ Modify your API route config of Next Auth, if you are using Pages Router, the fi

The following is an example of App Router:

<Tabs>

<TabItem value="v5" label="Next Auth v5">

```ts
import NextAuth from 'next-auth';

export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [
{
id: 'logto',
name: 'Logto',
type: 'oidc',
// You can get the issuer value from the Logto Application Details page,
// in the field "Issuer endpoint"
issuer: 'https://xxxx.logto.app/oidc',
clientId: '<logto-app-id>',
clientSecret: '<logto-app-secret>',
authorization: {
params: { scope: 'openid offline_access profile email' },
},
profile(profile) {
// You can customize the user profile mapping here
return {
id: profile.sub,
name: profile.name ?? profile.username,
email: profile.email,
image: profile.picture,
};
},
},
],
});
```

1. Replace the `issuer` URL with your Logto application's "Issuer endpoint".
2. Replace the `clientId` and `clientSecret` with your Logto application's ID and secret.
3. Customize the `profile` function to map the user profile to the Next Auth user object, the default mapping is shown in the example.

</TabItem>

<TabItem value="v4" label="Next Auth v4">

```ts
import NextAuth from 'next-auth';

Expand Down Expand Up @@ -61,3 +107,7 @@ export { handler as GET, handler as POST };
2. Replace the `clientId` and `clientSecret` with your Logto application's ID and secret.
3. Customize the `profile` function to map the user profile to the Next Auth user object, the default mapping is shown in the example.
4. Remember to set the `id_token_signed_response_alg` to `ES384`.

</TabItem>

</Tabs>
Loading