Skip to content

Commit

Permalink
feat: next auth v5
Browse files Browse the repository at this point in the history
  • Loading branch information
wangsijie committed Aug 4, 2024
1 parent e414401 commit cb1addf
Showing 1 changed file with 50 additions and 0 deletions.
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>

0 comments on commit cb1addf

Please sign in to comment.