{"record":{"id":"ec6a934013e66dbe","repo":"withastro/astro","slug":"please-use-astro-cookies-instead","errorCode":null,"errorMessage":"Please use Astro.cookies instead.","messagePattern":"Please use Astro\\.cookies instead\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/integrations/netlify/src/index.ts","lineNumber":596,"sourceCode":"\t\t\t\tcountry: { code: 'mock', name: 'Mock Country' },\n\t\t\t\tsubdivision: { code: 'SD', name: 'Mock Subdivision' },\n\t\t\t\ttimezone: 'UTC',\n\t\t\t\tlongitude: 0,\n\t\t\t\tlatitude: 0,\n\t\t\t},\n\t\t\tip:\n\t\t\t\ttypeof req.headers['x-nf-client-connection-ip'] === 'string'\n\t\t\t\t\t? req.headers['x-nf-client-connection-ip']\n\t\t\t\t\t: (req.socket.remoteAddress ?? '127.0.0.1'),\n\t\t\tserver: {\n\t\t\t\tregion: 'local-dev',\n\t\t\t},\n\t\t\trequestId:\n\t\t\t\ttypeof req.headers['x-nf-request-id'] === 'string'\n\t\t\t\t\t? req.headers['x-nf-request-id']\n\t\t\t\t\t: 'mock-netlify-request-id',\n\t\t\tget cookies(): never {\n\t\t\t\tthrow new Error('Please use Astro.cookies instead.');\n\t\t\t},\n\t\t\tjson: (input) => Response.json(input),\n\t\t\tlog: console.info,\n\t\t\tnext: () => {\n\t\t\t\tthrow new Error('`context.next` is not implemented for serverless functions');\n\t\t\t},\n\t\t\tget params(): never {\n\t\t\t\tthrow new Error(\"context.params don't contain any usable content in Astro.\");\n\t\t\t},\n\t\t\trewrite() {\n\t\t\t\tthrow new Error('context.rewrite is not available in Astro.');\n\t\t\t},\n\t\t};\n\n\t\treturn context;\n\t}\n\n\tlet routes: IntegrationResolvedRoute[];","sourceCodeStart":578,"sourceCodeEnd":614,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/integrations/netlify/src/index.ts#L578-L614","documentation":"Same mock-context pattern as the `url` getter: in dev, `context.cookies` is `get cookies(): never` and throws on access because Astro owns cookie access via `Astro.cookies`. Netlify's cookies API is intentionally unavailable inside Astro handlers to avoid double sources of truth.","triggerScenarios":"Calling `context.cookies.get(...)` / `.set(...)` in an Astro endpoint/middleware in dev. Reused Netlify Function code that operated on `context.cookies`. Enumerating the context object in dev.","commonSituations":"Porting Netlify Function cookie logic into Astro. Debug code that iterates context keys.","solutions":["Use `Astro.cookies.get(name)` / `Astro.cookies.set(name, value, options)` / `.delete(name)`.","Remove direct reads of `context.cookies` in dev paths.","If sharing code between Astro and plain Netlify Functions, branch on environment."],"exampleFix":"// before\nconst token = context.cookies.get('token');\n\n// after\nconst token = Astro.cookies.get('token')?.value;","handlingStrategy":"validation","validationCode":"function getCookie(Astro: any, name: string) {\n  return Astro.cookies.get(name)?.value;\n}","typeGuard":"function hasAstroCookies(Astro: any): Astro is { cookies: { get: (n: string) => any } } {\n  return !!Astro?.cookies && typeof Astro.cookies.get === 'function';\n}","tryCatchPattern":null,"preventionTips":["Use `Astro.cookies` exclusively for cookie access.","Branch shared code by environment when reusing Netlify Function logic.","Do not destructure the Netlify context in dev."],"tags":["netlify","dev-server","cookies","deprecation"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}