Next.js Discord

Discord Forum

How to set headers in api routes?

Unanswered
Naeemgg posted this in #help-forum
Open in Discord
I want to set jwt token in headers just like this
res.setHeader('Set-Cookie', serialize('token', token, { httpOnly: true, path: '/' }));
res.status(200).json({ message: 'Logged in successfully' });

but not sure how to do it.

1 Reply

Asian black bear
You use the cookies() function to set cookies.