-
-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/console/src/assets/docs/guides/web-next-auth/README.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import InlineNotification from '@/ds-components/InlineNotification'; | ||
import UriInputField from '@/mdx-components/UriInputField'; | ||
import Steps from '@/mdx-components/Steps'; | ||
import Step from '@/mdx-components/Step'; | ||
|
||
<Steps> | ||
|
||
<Step title="Prerequisites"> | ||
|
||
In this guide, we assume you have set up Next Auth in your Next.js project. If you haven't, check out the [Next Auth documentation](https://next-auth.js.org/getting-started/introduction) to get started. | ||
|
||
</Step> | ||
|
||
<Step title="Configure redirect URI"> | ||
|
||
<InlineNotification> | ||
In the following steps, we assume your app is running on <code>http://localhost:3000</code>. | ||
</InlineNotification> | ||
|
||
First, let’s enter your redirect URI. | ||
|
||
<UriInputField name="redirectUris" defaultValue="http://localhost:3000/api/auth/callback/logto" /> | ||
|
||
Don't forget to click the **Save** button. | ||
|
||
</Step> | ||
|
||
<Step title="Configure the provider"> | ||
|
||
Modify your API route config of Next Auth, if you are using Pages Router, the file is in `pages/api/auth/[...nextauth].js`, if you are using App Router, the file is in `app/api/auth/[...nextauth]/router.ts`. | ||
|
||
The following is an example of App Router: | ||
|
||
<pre> | ||
<code className="language-ts"> | ||
{`import NextAuth from 'next-auth'; | ||
const handler = NextAuth({ | ||
providers: [ | ||
{ | ||
id: 'logto', | ||
name: 'Logto', | ||
type: 'oauth', | ||
// You can get the well-known URL from the Logto Application Details page, | ||
// in the field "OpenID Provider configuration endpoint" | ||
wellKnown: '${props.endpoint}oidc/.well-known/openid-configuration', | ||
authorization: { params: { scope: 'openid offline_access profile email' } }, | ||
clientId: '${props.app.id}'', | ||
clientSecret: '${props.app.secret}', | ||
client: { | ||
id_token_signed_response_alg: 'ES384', | ||
}, | ||
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, | ||
}; | ||
}, | ||
}, | ||
], | ||
}); | ||
export { handler as GET, handler as POST };`} | ||
</code> | ||
</pre> | ||
|
||
</Step> | ||
|
||
<Step title="Checkpoint: Test Logto and Next Auth integration"> | ||
|
||
Now, you can test your application to see if the authentication works as expected. | ||
|
||
</Step> | ||
|
||
</Steps> |
3 changes: 3 additions & 0 deletions
3
packages/console/src/assets/docs/guides/web-next-auth/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"order": 1.3 | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/console/src/assets/docs/guides/web-next-auth/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ApplicationType } from '@logto/schemas'; | ||
|
||
import { type GuideMetadata } from '../types'; | ||
|
||
const metadata: Readonly<GuideMetadata> = Object.freeze({ | ||
name: 'Next Auth', | ||
description: 'Authentication for Next.js.', | ||
target: ApplicationType.Traditional, | ||
}); | ||
|
||
export default metadata; |
25 changes: 25 additions & 0 deletions
25
packages/console/src/assets/docs/guides/web-next-auth/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.