#context.cookies undefined
2 messages · Page 1 of 1 (latest)
Based on the information provided in the extracts, it seems like you're trying to access cookies in your Astro application.
Astro provides a utility to read and modify cookies through Astro.cookies or context.cookies in server-side rendering mode. You can use methods like get, set, has, and delete to manipulate cookies.
Here's an example of how you can use it:
let counter = 0
if (Astro.cookies.has("counter")) {
const cookie = Astro.cookies.get("counter")
counter = cookie.number() + 1
}
Astro.cookies.set("counter", counter)
(Source: Astro Documentation (https://docs.astro.build/en/guides/server-side-rendering/))
However, please note that cookies are not available in static site generation (SSG) mode. If you're using SSG, you might see a warning like this:
[ssg] Headers are not exposed in static (SSG) output mode. To enable headers: set `output: "server"` in your config file.
(Source: GitHub Issue (https://github.com/withastro/astro/issues/6499))