Skip to content

Commit 09f5aab

Browse files
committed
docs: fix source links
1 parent 9dd2bce commit 09f5aab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+156
-146
lines changed

docs/docs/configuration/initialization.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ title: Initialization
55

66
The main entry point of NextAuth.js is the `NextAuth` method that you import from `next-auth`. It handles different types of requests, as defined in the [REST API](../getting-started/rest-api.md) section.
77

8-
98
:::info
109
NextAuth.js cannot use the run [Edge Runtime](https://nextjs.org/docs/api-reference/edge-runtime) for initialization. The upcoming [`@auth/nextjs` library](https://authjs.dev/reference/nextjs) (which will replace `next-auth`) on the other hand will be fully compatible.
1110
:::
1211

1312
You can initialize NextAuth.js in a few different ways.
1413

1514
## Simple initialization
15+
1616
### API Routes (`pages`)
1717

1818
In Next.js, you can define an API route that will catch all requests that begin with a certain path. Conveniently, this is called [Catch all API routes](https://nextjs.org/docs/api-routes/dynamic-api-routes#catch-all-api-routes).
@@ -62,7 +62,6 @@ Instead, `NextAuth` will receive the first two arguments of a Route Handler, and
6262

6363
If you have a specific use case and need to make NextAuth.js do something slightly different than what it is designed for, keep in mind, the `[...nextauth].ts` config file is just **a regular [API Route](https://nextjs.org/docs/api-routes/introduction)**.
6464

65-
6665
That said, you can initialize NextAuth.js like this:
6766

6867
```ts title="/pages/api/auth/[...nextauth].ts"
@@ -148,7 +147,7 @@ export default async function auth(req, res) {
148147
}
149148
```
150149

151-
For more details on all available actions and which methods are supported, please check out the [REST API documentation](/getting-started/rest-api) or the appropriate area in [the source code](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/core/index.ts)
150+
For more details on all available actions and which methods are supported, please check out the [REST API documentation](/getting-started/rest-api) or the appropriate area in [the source code](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/core/index.ts)
152151

153152
This way of initializing `NextAuth` is very powerful, but should be used sparingly.
154153

docs/docs/configuration/pages.md

+30-15
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ Example: `/auth/error?error=Configuration`
4444

4545
The following errors are passed as error query parameters to the default or overridden sign-in page:
4646

47-
- **OAuthSignin**: Error in constructing an authorization URL ([1](https://github.com/nextauthjs/next-auth/blob/457952bb5abf08b09861b0e5da403080cd5525be/src/server/lib/signin/oauth.js), [2](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/core/lib/oauth/pkce-handler.ts), [3](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/core/lib/oauth/state-handler.ts)),
48-
- **OAuthCallback**: Error in handling the response ([1](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/core/lib/oauth/callback.ts), [2](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/core/lib/oauth/pkce-handler.ts), [3](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/core/lib/oauth/state-handler.ts)) from an OAuth provider.
47+
- **OAuthSignin**: Error in constructing an authorization URL ([1](https://github.com/nextauthjs/next-auth/blob/457952bb5abf08b09861b0e5da403080cd5525be/src/server/lib/signin/oauth.js), [2](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/core/lib/oauth/pkce-handler.ts), [3](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/core/lib/oauth/state-handler.ts)),
48+
- **OAuthCallback**: Error in handling the response ([1](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/core/lib/oauth/callback.ts), [2](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/core/lib/oauth/pkce-handler.ts), [3](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/core/lib/oauth/state-handler.ts)) from an OAuth provider.
4949
- **OAuthCreateAccount**: Could not create OAuth provider user in the database.
5050
- **EmailCreateAccount**: Could not create email provider user in the database.
51-
- **Callback**: Error in the [OAuth callback handler route](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/core/routes/callback.ts)
51+
- **Callback**: Error in the [OAuth callback handler route](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/core/routes/callback.ts)
5252
- **OAuthAccountNotLinked**: If the email on the account is already linked, but not with this OAuth account
5353
- **EmailSignin**: Sending the e-mail with the verification token failed
5454
- **CredentialsSignin**: The `authorize` callback returned `null` in the [Credentials provider](/providers/credentials). We don't recommend providing information about which part of the credentials were wrong, as it might be abused by malicious hackers.
@@ -78,12 +78,17 @@ In addition, you can define a `theme.brandColor` to define a custom accent color
7878
In order to get the available authentication providers and the URLs to use for them, you can make a request to the API endpoint `/api/auth/providers`:
7979

8080
```tsx title="pages/auth/signin.tsx"
81-
import type { GetServerSidePropsContext, InferGetServerSidePropsType } from "next";
81+
import type {
82+
GetServerSidePropsContext,
83+
InferGetServerSidePropsType,
84+
} from "next"
8285
import { getProviders, signIn } from "next-auth/react"
8386
import { getServerSession } from "next-auth/next"
84-
import { authOptions } from "../api/auth/[...nextauth]";
87+
import { authOptions } from "../api/auth/[...nextauth]"
8588

86-
export default function SignIn({ providers }: InferGetServerSidePropsType<typeof getServerSideProps>) {
89+
export default function SignIn({
90+
providers,
91+
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
8792
return (
8893
<>
8994
{Object.values(providers).map((provider) => (
@@ -98,17 +103,17 @@ export default function SignIn({ providers }: InferGetServerSidePropsType<typeof
98103
}
99104

100105
export async function getServerSideProps(context: GetServerSidePropsContext) {
101-
const session = await getServerSession(context.req, context.res, authOptions);
102-
106+
const session = await getServerSession(context.req, context.res, authOptions)
107+
103108
// If the user is already logged in, redirect.
104109
// Note: Make sure not to redirect to the same page
105110
// To avoid an infinite loop!
106111
if (session) {
107-
return { redirect: { destination: "/" } };
112+
return { redirect: { destination: "/" } }
108113
}
109114

110-
const providers = await getProviders();
111-
115+
const providers = await getProviders()
116+
112117
return {
113118
props: { providers: providers ?? [] },
114119
}
@@ -122,10 +127,15 @@ There is another, more fully styled example signin page available [here](https:/
122127
If you create a custom sign in form for email sign in, you will need to submit both fields for the **email** address and **csrfToken** from **/api/auth/csrf** in a POST request to **/api/auth/signin/email**.
123128

124129
```tsx title="pages/auth/email-signin.tsx"
125-
import type { GetServerSidePropsContext, InferGetServerSidePropsType } from "next";
130+
import type {
131+
GetServerSidePropsContext,
132+
InferGetServerSidePropsType,
133+
} from "next"
126134
import { getCsrfToken } from "next-auth/react"
127135

128-
export default function SignIn({ csrfToken }: InferGetServerSidePropsType<typeof getServerSideProps>) {
136+
export default function SignIn({
137+
csrfToken,
138+
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
129139
return (
130140
<form method="post" action="/api/auth/signin/email">
131141
<input name="csrfToken" type="hidden" defaultValue={csrfToken} />
@@ -157,10 +167,15 @@ signIn("email", { email: "[email protected]" })
157167
If you create a sign in form for credentials based authentication, you will need to pass a **csrfToken** from **/api/auth/csrf** in a POST request to **/api/auth/callback/credentials**.
158168

159169
```tsx title="pages/auth/credentials-signin.tsx"
160-
import type { GetServerSidePropsContext, InferGetServerSidePropsType } from "next";
170+
import type {
171+
GetServerSidePropsContext,
172+
InferGetServerSidePropsType,
173+
} from "next"
161174
import { getCsrfToken } from "next-auth/react"
162175

163-
export default function SignIn({ csrfToken }: InferGetServerSidePropsType<typeof getServerSideProps>) {
176+
export default function SignIn({
177+
csrfToken,
178+
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
164179
return (
165180
<form method="post" action="/api/auth/callback/credentials">
166181
<input name="csrfToken" type="hidden" defaultValue={csrfToken} />

docs/docs/configuration/providers/oauth.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ providers: [
359359
360360
## Built-in providers
361361
362-
NextAuth.js comes with a set of built-in providers. You can find them [here](https://github.com/nextauthjs/next-auth/tree/main/packages/next-auth/src/providers). Each built-in provider has its own documentation page:
362+
NextAuth.js comes with a set of built-in providers. You can find them [here](https://github.com/nextauthjs/next-auth/tree/v4/packages/next-auth/src/providers). Each built-in provider has its own documentation page:
363363
364364
<div className="provider-name-list">
365365
{Object.entries(require("../../../providers.json"))

docs/docs/getting-started/client.md

+17-20
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,14 @@ export default function Page() {
172172
return (
173173
<>
174174
<p>Signed in as {session.user.name}</p>
175-
175+
176176
{/* Update the value by sending it to the backend. */}
177-
<button onClick={() => update({ name: "John Doe" })}>
178-
Edit name
179-
</button>
177+
<button onClick={() => update({ name: "John Doe" })}>Edit name</button>
180178
{/*
181-
* Only trigger a session update, assuming you already updated the value server-side.
182-
* All `useSession().data` references will be updated.
183-
*/}
184-
<button onClick={() => update()}>
185-
Edit name
186-
</button>
179+
* Only trigger a session update, assuming you already updated the value server-side.
180+
* All `useSession().data` references will be updated.
181+
*/}
182+
<button onClick={() => update()}>Edit name</button>
187183
</>
188184
)
189185
}
@@ -245,7 +241,7 @@ The `update()` method won't sync between tabs as the `refetchInterval` and `refe
245241
:::
246242

247243
```tsx title="pages/profile.tsx"
248-
import {useEffect} from "react"
244+
import { useEffect } from "react"
249245
import { useSession } from "next-auth/react"
250246

251247
export default function Page() {
@@ -263,18 +259,17 @@ export default function Page() {
263259
// Listen for when the page is visible, if the user switches tabs
264260
// and makes our tab visible again, re-fetch the session
265261
useEffect(() => {
266-
const visibilityHandler = () => document.visibilityState === "visible" && update()
262+
const visibilityHandler = () =>
263+
document.visibilityState === "visible" && update()
267264
window.addEventListener("visibilitychange", visibilityHandler, false)
268-
return () => window.removeEventListener("visibilitychange", visibilityHandler, false)
265+
return () =>
266+
window.removeEventListener("visibilitychange", visibilityHandler, false)
269267
}, [update])
270268

271-
return (
272-
<pre>
273-
{JSON.stringify(session, null, 2)}
274-
</pre>
275-
)
269+
return <pre>{JSON.stringify(session, null, 2)}</pre>
276270
}
277271
```
272+
278273
---
279274

280275
## getSession()
@@ -288,7 +283,7 @@ On the server side, **this is still available to use**, however, we recommend us
288283

289284
This helper is helpful in case you want to read the session outside of the context of React.
290285

291-
When called, `getSession()` will send a request to `/api/auth/session` and returns a promise with a [session object](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/core/types.ts#L407-L425), or `null` if no session exists.
286+
When called, `getSession()` will send a request to `/api/auth/session` and returns a promise with a [session object](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/core/types.ts#L407-L425), or `null` if no session exists.
292287

293288
```js
294289
async function myFunction() {
@@ -520,7 +515,7 @@ where `data.url` is the validated URL you can redirect the user to without any f
520515
## SessionProvider
521516

522517
:::note
523-
If you are using the App Router, we encourage you to use [`getServerSession`](/configuration/nextjs#getserversession) in server contexts instead. (`SessionProvider` *can* be used in the App Router, which might be the easier choice if you are migrating from pages.)
518+
If you are using the App Router, we encourage you to use [`getServerSession`](/configuration/nextjs#getserversession) in server contexts instead. (`SessionProvider` _can_ be used in the App Router, which might be the easier choice if you are migrating from pages.)
524519
:::
525520

526521
Using the supplied `<SessionProvider>` allows instances of `useSession()` to share the session object across components, by using [React Context](https://react.dev/learn/passing-data-deeply-with-context) under the hood. It also takes care of keeping the session updated and synced between tabs/windows.
@@ -633,11 +628,13 @@ See [**the Next.js documentation**](https://nextjs.org/docs/advanced-features/cu
633628
:::
634629

635630
### Custom base path
631+
636632
When your Next.js application uses a custom base path, set the `NEXTAUTH_URL` environment variable to the route to the API endpoint in full - as in the example below and as explained [here](/configuration/options#nextauth_url).
637633

638634
Also, make sure to pass the `basePath` page prop to the `<SessionProvider>` – as in the example below – so your custom base path is fully configured and used by NextAuth.js.
639635

640636
#### Example
637+
641638
In this example, the custom base path used is `/custom-route`.
642639

643640
```

docs/docs/providers/42.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ https://profile.intra.42.fr/oauth/applications/new
1919

2020
The **42 School Provider** comes with a set of default options:
2121

22-
- [42 School Provider options](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/providers/42-school.ts)
22+
- [42 School Provider options](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/providers/42-school.ts)
2323

2424
You can override any of the options to suit your own use case.
2525

docs/docs/providers/apple.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ https://developer.apple.com/account/resources/identifiers/list/serviceId
1515

1616
The **Apple Provider** comes with a set of default options:
1717

18-
- [Apple Provider options](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/providers/apple.ts)
18+
- [Apple Provider options](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/providers/apple.ts)
1919

2020
You can override any of the options to suit your own use case.
2121

docs/docs/providers/atlassian.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ https://developer.atlassian.com/cloud/jira/platform/oauth-2-authorization-code-g
1111

1212
The **Atlassian Provider** comes with a set of default options:
1313

14-
- [Atlassian Provider options](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/providers/atlassian.ts)
14+
- [Atlassian Provider options](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/providers/atlassian.ts)
1515

1616
You can override any of the options to suit your own use case.
1717

docs/docs/providers/authentik.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ https://goauthentik.io/docs/providers/oauth2
1111

1212
The **Authentik Provider** comes with a set of default options:
1313

14-
- [Authentik Provider options](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/providers/authentik.ts)
14+
- [Authentik Provider options](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/providers/authentik.ts)
1515

1616
You can override any of the options to suit your own use case.
1717

docs/docs/providers/azure-ad-b2c.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ https://docs.microsoft.com/azure/active-directory-b2c/tutorial-create-tenant
2626

2727
The **Azure Active Directory Provider** comes with a set of default options:
2828

29-
- [Azure Active Directory Provider options](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/providers/azure-ad-b2c.ts)
29+
- [Azure Active Directory Provider options](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/providers/azure-ad-b2c.ts)
3030

3131
You can override any of the options to suit your own use case.
3232

docs/docs/providers/battlenet.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ https://develop.battle.net/access/clients
1515

1616
The **Battle.net Provider** comes with a set of default options:
1717

18-
- [Battle.net Provider options](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/providers/battlenet.js)
18+
- [Battle.net Provider options](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/providers/battlenet.js)
1919

2020
You can override any of the options to suit your own use case.
2121

docs/docs/providers/box.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ https://developer.box.com/guides/sso-identities-and-app-users/connect-okta-to-ap
1515

1616
The **Box Provider** comes with a set of default options:
1717

18-
- [Box Provider options](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/providers/box.js)
18+
- [Box Provider options](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/providers/box.js)
1919

2020
You can override any of the options to suit your own use case.
2121

docs/docs/providers/boxyhq-saml.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Check out the [documentation](https://boxyhq.com/docs/jackson/saml-flow#2-saml-c
1919

2020
The **BoxyHQ SAML Provider** comes with a set of default options:
2121

22-
- [BoxyHQ Provider options](https://github.com/nextauthjs/next-auth/tree/main/packages/next-auth/src/providers/boxyhq-saml.ts)
22+
- [BoxyHQ Provider options](https://github.com/nextauthjs/next-auth/tree/v4/packages/next-auth/src/providers/boxyhq-saml.ts)
2323

2424
You can override any of the options to suit your own use case.
2525

docs/docs/providers/bungie.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ https://www.bungie.net/en/Application
1515

1616
The **Bungie Provider** comes with a set of default options:
1717

18-
- [Bungie Provider options](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/providers/bungie.js)
18+
- [Bungie Provider options](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/providers/bungie.js)
1919

2020
You can override any of the options to suit your own use case.
2121

docs/docs/providers/cognito.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You need to select your AWS region to go the the Cognito dashboard.
1717

1818
The **Amazon Cognito Provider** comes with a set of default options:
1919

20-
- [Amazon Cognito Provider options](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/providers/cognito.ts)
20+
- [Amazon Cognito Provider options](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/providers/cognito.ts)
2121

2222
You can override any of the options to suit your own use case.
2323

docs/docs/providers/coinbase.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ https://www.coinbase.com/settings/api
1515

1616
The **Coinbase Provider** comes with a set of default options:
1717

18-
- [Coinbase Provider options](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/providers/coinbase.js)
18+
- [Coinbase Provider options](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/providers/coinbase.js)
1919

2020
You can override any of the options to suit your own use case.
2121

docs/docs/providers/dropbox.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ https://www.dropbox.com/developers/apps
1515

1616
The **Dropbox Provider** comes with a set of default options:
1717

18-
- [Dropbox Provider options](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/providers/dropbox.js)
18+
- [Dropbox Provider options](https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/providers/dropbox.js)
1919

2020
You can override any of the options to suit your own use case.
2121

0 commit comments

Comments
 (0)