{"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/3578d45d34226d63cff3d261c971c221de6794d2/packages/integrations/netlify/src/index.ts#L578-L614","documentation":"The mock dev Context built by getLocalDevNetlifyContext implements cookies as a throwing getter. Astro already exposes request cookies via Astro.cookies, so the adapter deliberately rejects context.cookies in local dev instead of returning a half-working duplicate.","triggerScenarios":"Calling locals.runtime.context.cookies.get/set/... in a page, endpoint, or middleware while running under astro dev with the Netlify adapter.","commonSituations":"Netlify Functions snippets that use context.cookies; ported Next.js/Express cookie code wired to the Netlify Context; helper modules shared between functions and Astro routes.","solutions":["Use Astro.cookies.get(name) / Astro.cookies.set(...) in pages and API routes","In middleware use context.cookies (Astro's own middleware context), not the Netlify Context","Guard any remaining Netlify-specific cookie access with try/catch or restrict it to deployed functions"],"exampleFix":"// before\nconst session = locals.runtime.context.cookies.get('session');\n// after\nconst session = Astro.cookies.get('session');","handlingStrategy":"fallback","validationCode":"const ctx = locals.runtime?.context;\nconst isLocalDev = ctx?.deploy?.context === 'dev';\nconst session = isLocalDev ? Astro.cookies.get('session')?.value : ctx!.cookies.get?.('session');","typeGuard":"function safeNetlifyCookies<T>(context: any, fallback: T): T {\n  try {\n    return (context.cookies ?? fallback) as T;\n  } catch {\n    return fallback;\n  }\n}","tryCatchPattern":"let cookies = Astro.cookies; // always available in Astro\ntry {\n  cookies = locals.runtime.context.cookies; // throws in local dev\n} catch {\n  // keep Astro.cookies\n}","preventionTips":["Read/write cookies via Astro.cookies in pages, endpoints, and middleware","Keep Netlify Context usage to waitUntil and deploy metadata","Add a dev-time smoke test that hits every cookie-reading route"],"tags":["netlify","local-dev","context","cookies"],"backgroundTag":"unsupported-api-stub","analyzedSha":"3578d45d34226d63cff3d261c971c221de6794d2","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}