When attempting to set cookies in oak, the cookies property of the context is never changed and the value is always returned undefined even when using the example in their docs.
app.use(async ctx => {
try {
const lastVisit = await ctx.cookies.get('lastVisit')
console.log(lastVisit)
await ctx.cookies.set('lastVisit', new Date().toISOString())
if (lastVisit) {
console.log(`Welcome back. You were last here at ${lastVisit}.`)
} else {
console.log(`Welcome, I haven't seen your before.`)
}
} catch (error) {
console.error(error)
}
})
Am I not accessing the cookies the correct way?
Here's an example based on the code you shared which shows how to read and set a cookie (and also store data in the context's state) using Oak. You can simply copy + paste into a playground or project on Deno Deploy to try it: