Skip to content

Commit 9ffcd04

Browse files
authored
Update "API Routes" to "Route Handlers" in Next.js App Router documentation (#1689)
1 parent a2d0333 commit 9ffcd04

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

docs/pages/guides/validate-session-cookies/nextjs-app.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ You can get the cookie name with `Lucia.sessionCookieName` and validate the sess
88

99
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.
1010

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).
1212

1313
```ts
1414
import { lucia } from "@/utils/auth";
@@ -74,7 +74,7 @@ async function Page() {
7474
}
7575
```
7676

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.
7878

7979
```ts
8080
// middleware.ts

docs/pages/tutorials/github-oauth/nextjs-app.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default async function Page() {
9999

100100
## Create authorization URL
101101

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.
103103

104104
```ts
105105
// app/login/github/route.ts
@@ -125,7 +125,7 @@ export async function GET(): Promise<Response> {
125125

126126
## Validate callback
127127

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.
129129

130130
```ts
131131
// app/login/github/callback/route.ts
@@ -211,7 +211,7 @@ interface GitHubUser {
211211

212212
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.
213213

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).
215215

216216
```ts
217217
import { cookies } from "next/headers";

docs/pages/tutorials/username-and-password/nextjs-app.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ async function login(_: any, formData: FormData): Promise<ActionResult> {
265265

266266
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.
267267

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).
269269

270270
```ts
271271
import { cookies } from "next/headers";

0 commit comments

Comments
 (0)