From a6b40317294308f2d67240b789a8bbfcca694703 Mon Sep 17 00:00:00 2001 From: AkashPattanaik Date: Wed, 2 Nov 2022 09:16:40 +0530 Subject: [PATCH] Add `path` for information in cookie setting (#42146) ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [x] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [x] Make sure the linting passes by running `pnpm build && pnpm lint` - [x] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) --- docs/api-routes/request-helpers.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/api-routes/request-helpers.md b/docs/api-routes/request-helpers.md index 28be26d66cf4273..3a3f6a0e83e6ac7 100644 --- a/docs/api-routes/request-helpers.md +++ b/docs/api-routes/request-helpers.md @@ -128,7 +128,8 @@ import { setCookie } from '../../utils/cookies' const handler = (req: NextApiRequest, res: NextApiResponse) => { // Calling our pure function using the `res` object, it will add the `set-cookie` header - setCookie(res, 'Next.js', 'api-middleware!') + // Add the `set-cookie` header on the main domain and expire after 30 days + setCookie(res, 'Next.js', 'api-middleware!', { path: '/', maxAge: 2592000 }) // Return the `set-cookie` header so we can display it in the browser and show that it works! res.end(res.getHeader('Set-Cookie')) }