I call Set-Cookie on the serverside
export async function post (req, res, next) {
const jwtToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImNocmlzLmNhcnJpbmd0b25AZ2xldy5pbyIsImlhdCI6MTU5OTA1NDcxNn0.NaEO1ywtCsD55oKb7JSaQbtzidySiy7Bld7Bs63_wuU'
res.setHeader('Content-Type', 'application/json')
res.setHeader('Set-Cookie', `jwtToken=${ jwtToken }; Max-Age=86400;`)
res.end(JSON.stringify({ jwtToken }))
}
jwtToken cookie shown on request & response
Set-Cookie: jwtToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImNocmlzLmNhcnJpbmd0b25AZ2xldy5pbyIsImlhdCI6MTU5OTA1NDcxNn0.NaEO1ywtCsD55oKb7JSaQbtzidySiy7Bld7Bs63_wuU; Max-Age=86400;
I've tried the browsers Brave and Chrome, why is document.cookie an empty string in both browsers please?
Cookie has /api
path in Application > Cookies and is accessed from /sign-in-with-token
path.
If a cookie is set with path=/admin, it's visible at pages /admin and /admin/something, but not at /home or /adminpage.
https://javascript.info/cookie#path
Maybe let's try to explicitly set the path to /
:
res.setHeader('Set-Cookie', `jwtToken=${ jwtToken }; Max-Age=86400; Path=/`)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.