简体   繁体   中英

how can i insert the token to the local storage?

enter image description here enter image description here How can I set the token in the local storage?now it is sent in the response body, should I use res.setheader?and if yes what to insert to it the token so that it will be set to local storage?

const token = jwt.sign({
    name: result[0].name
  },
  'somesupersecretsecret', {
    expiresIn: '1h'
  }
);
res.status(200).json({
token: token,
userId: "userid"
})

.catch(err => {
if (!err.statusCode) {
  err.statusCode = 500;
}
next(err);
});
}
});

You can't store any data in the browser's local storage from your Node.js server-side (backend) code. You need to carry this data from backend to frontend JS code before you attempt to store the same in the browser's local storage. Usually tokens are embedded into the headers.

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