You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/pages/guides/validate-session-cookies/nextjs-app.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ You can get the cookie name with `Lucia.sessionCookieName` and validate the sess
8
8
9
9
We recommend wrapping the function with [`cache()`](https://nextjs.org/docs/app/building-your-application/caching#react-cache-function) so it can be called multiple times without incurring multiple database calls.
10
10
11
-
**CSRF protection is only handled by Next.js when using form actions.** If you're using API routes, it must be implemented by yourself (see below).
11
+
**CSRF protection is only handled by Next.js when using form actions.** If you're using Route Handlers, it must be implemented by yourself (see below).
12
12
13
13
```ts
14
14
import { lucia } from"@/utils/auth";
@@ -74,7 +74,7 @@ async function Page() {
74
74
}
75
75
```
76
76
77
-
For API routes, since Next.js does not implement CSRF protection for API routes, **CSRF protection must be implemented when dealing with forms** if you're dealing with forms. This can be easily done by comparing the `Origin` and `Host` header. We recommend using middleware for this.
77
+
For Route Handlers, since Next.js does not implement CSRF protection for Route Handlers, **CSRF protection must be implemented when dealing with forms** if you're dealing with forms. This can be easily done by comparing the `Origin` and `Host` header. We recommend using middleware for this.
Copy file name to clipboardexpand all lines: docs/pages/tutorials/github-oauth/nextjs-app.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -99,7 +99,7 @@ export default async function Page() {
99
99
100
100
## Create authorization URL
101
101
102
-
Create an API route in `app/login/github/route.ts`. Generate a new state, create a new authorization URL with createAuthorizationURL(), store the state, and redirect the user to the authorization URL. The user will be prompted to sign in with GitHub.
102
+
Create an Route Handlers in `app/login/github/route.ts`. Generate a new state, create a new authorization URL with createAuthorizationURL(), store the state, and redirect the user to the authorization URL. The user will be prompted to sign in with GitHub.
103
103
104
104
```ts
105
105
// app/login/github/route.ts
@@ -125,7 +125,7 @@ export async function GET(): Promise<Response> {
125
125
126
126
## Validate callback
127
127
128
-
Create an API route in `app/login/github/callback/route.ts` to handle the callback. First, get the state from the cookie and the search params and compare them. Validate the authorization code in the search params with `validateAuthorizationCode()`. This will throw an [`OAuth2RequestError`](https://oslo.js.org/reference/oauth2/OAuth2RequestError) if the code or credentials are invalid. After validating the code, get the user's profile using the access token. Check if the user is already registered with the GitHub ID, and create a new user if they aren't. Finally, create a new session and set the session cookie.
128
+
Create an Route Handlers in `app/login/github/callback/route.ts` to handle the callback. First, get the state from the cookie and the search params and compare them. Validate the authorization code in the search params with `validateAuthorizationCode()`. This will throw an [`OAuth2RequestError`](https://oslo.js.org/reference/oauth2/OAuth2RequestError) if the code or credentials are invalid. After validating the code, get the user's profile using the access token. Check if the user is already registered with the GitHub ID, and create a new user if they aren't. Finally, create a new session and set the session cookie.
129
129
130
130
```ts
131
131
// app/login/github/callback/route.ts
@@ -211,7 +211,7 @@ interface GitHubUser {
211
211
212
212
Create `validateRequest()`. This will check for the session cookie, validate it, and set a new cookie if necessary. Make sure to catch errors when setting cookies and wrap the function with `cache()` to prevent unnecessary database calls. To learn more, see the [Validating requests](/guides/validate-session-cookies/nextjs-app) page.
213
213
214
-
CSRF protection should be implemented but Next.js handles it when using form actions (but not for API routes).
214
+
CSRF protection should be implemented but Next.js handles it when using form actions (but not for Route Handlers).
Create `validateRequest()`. This will check for the session cookie, validate it, and set a new cookie if necessary. Make sure to catch errors when setting cookies and wrap the function with `cache()` to prevent unnecessary database calls. To learn more, see the [Validating requests](/guides/validate-session-cookies/nextjs-app) page.
267
267
268
-
CSRF protection should be implemented but Next.js handles it when using form actions (but not for API routes).
268
+
CSRF protection should be implemented but Next.js handles it when using form actions (but not for Route Handlers).
0 commit comments