简体   繁体   中英

Accessing universal-cookie set by React from NodeJS

My ReactJS app creates an httpOnly universal-cookie with the token after the user logs in. The code is as follows,

cookies.set('token', res.data.token, { path: '/', httpOnly: true });

In my NodeJS backend code, I am trying to access this cookie by using the following code,

const cookies = req.universalCookies.get('token')

When I console.log the cookies variable it shows undefined .

What am I doing wrong? How can I fix it?

Is there any better and safe method that works? If yes then please let me know about that too.

Node.js cannot access the cookie because it is server-side. You can solve it by sending a token from the Header.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM