Unverified Commit 5023f5ae authored by Robin Singh's avatar Robin Singh Committed by GitHub

Cannot redeclare block-scoped variable 'cookie'. (#45079)

## 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)
parent c30c14da
...@@ -164,7 +164,7 @@ import type { NextRequest } from 'next/server' ...@@ -164,7 +164,7 @@ import type { NextRequest } from 'next/server'
export function middleware(request: NextRequest) { export function middleware(request: NextRequest) {
// Assume a "Cookie:nextjs=fast" header to be present on the incoming request // Assume a "Cookie:nextjs=fast" header to be present on the incoming request
// Getting cookies from the request using the `RequestCookies` API // Getting cookies from the request using the `RequestCookies` API
const cookie = request.cookies.get('nextjs')?.value let cookie = request.cookies.get('nextjs')?.value
console.log(cookie) // => 'fast' console.log(cookie) // => 'fast'
const allCookies = request.cookies.getAll() const allCookies = request.cookies.getAll()
console.log(allCookies) // => [{ name: 'nextjs', value: 'fast' }] console.log(allCookies) // => [{ name: 'nextjs', value: 'fast' }]
...@@ -181,7 +181,7 @@ export function middleware(request: NextRequest) { ...@@ -181,7 +181,7 @@ export function middleware(request: NextRequest) {
value: 'fast', value: 'fast',
path: '/test', path: '/test',
}) })
const cookie = response.cookies.get('vercel') cookie = response.cookies.get('vercel')
console.log(cookie) // => { name: 'vercel', value: 'fast', Path: '/test' } console.log(cookie) // => { name: 'vercel', value: 'fast', Path: '/test' }
// The outgoing response will have a `Set-Cookie:vercel=fast;path=/test` header. // The outgoing response will have a `Set-Cookie:vercel=fast;path=/test` header.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment