From c261d0d0dfb869484f1b4ce6c4bfc577fd5369f2 Mon Sep 17 00:00:00 2001 From: Lee Robinson Date: Sun, 24 Dec 2023 10:02:50 -0600 Subject: [PATCH] docs: clarify setting and reading cookies from Route Handlers (#59915) Replaces https://github.com/vercel/next.js/pull/57052 --- .../01-routing/10-route-handlers.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/02-app/01-building-your-application/01-routing/10-route-handlers.mdx b/docs/02-app/01-building-your-application/01-routing/10-route-handlers.mdx index 4c3f1c553d3c4..1fb2567c891ca 100644 --- a/docs/02-app/01-building-your-application/01-routing/10-route-handlers.mdx +++ b/docs/02-app/01-building-your-application/01-routing/10-route-handlers.mdx @@ -229,9 +229,9 @@ Route Handlers can be used with dynamic functions from Next.js, like [`cookies`] #### Cookies -You can read cookies with [`cookies`](/docs/app/api-reference/functions/cookies) from `next/headers`. This server function can be called directly in a Route Handler, or nested inside of another function. +You can read or set cookies with [`cookies`](/docs/app/api-reference/functions/cookies) from `next/headers`. This server function can be called directly in a Route Handler, or nested inside of another function. -This `cookies` instance is read-only. To set cookies, you need to return a new `Response` using the [`Set-Cookie`](https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie) header. +Alternatively, you can return a new `Response` using the [`Set-Cookie`](https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie) header. ```ts filename="app/api/route.ts" switcher import { cookies } from 'next/headers' @@ -261,7 +261,7 @@ export async function GET(request) { } ``` -Alternatively, you can use abstractions on top of the underlying Web APIs to read cookies ([`NextRequest`](/docs/app/api-reference/functions/next-request)): +You can also use the underlying Web APIs to read cookies from the request ([`NextRequest`](/docs/app/api-reference/functions/next-request)): ```ts filename="app/api/route.ts" switcher import { type NextRequest } from 'next/server' @@ -311,7 +311,7 @@ export async function GET(request) { } ``` -Alternatively, you can use abstractions on top of the underlying Web APIs to read headers ([`NextRequest`](/docs/app/api-reference/functions/next-request)): +You can also use the underlying Web APIs to read headers from the request ([`NextRequest`](/docs/app/api-reference/functions/next-request)): ```ts filename="app/api/route.ts" switcher import { type NextRequest } from 'next/server'