request.cookies
The parsed request cookies, available when the cookie plugin is registered.
Syntax
request.cookies Returns
object — A map of cookie names to string values.
Examples
import Fastify from 'fastify';
import cookie from '@fastify/cookie';
const app = Fastify();
await app.register(cookie, { secret: process.env.COOKIE_SECRET });
app.get('/session', async (req) => {
const sid = req.cookies.sid;
const unsigned = sid ? req.unsignCookie(sid) : null;
return { valid: unsigned?.valid ?? false };
});
Notes
request.cookies exists only after registering @fastify/cookie. Use
req.unsignCookie() to verify signed cookies when a secret is configured.