VUE, login is successful. If the backend returns cookie, the foreground cannot get it.

Log in successfully. The backend returns a userId, and then you can see in cookie that the name and the value
name are userId,userId, which varies according to each user

.

I want to use this to determine whether to log in in the route, but I can"t get it

or do I want to store this userId, on my own local localstorage?

Note: make sure that the KEY of cookie should be fixed, not set dynamically, so you can"t get it all the time

Mar.20,2021

when logging in, the operation of cookie should be done in HTTP header by the back end, not by the front end, because the front end is open to users, so letting users know how you operate cookie can easily lead to unexpected security risks.

if you are cross-domain, you need to add withCredentials: true to solve the problem.


if you can see the value of the cookie and the value, in the frontend, you can also get the cookie, in the route. You can only operate on the document.cookie (you can encapsulate several methods to determine whether cookie exists, obtain the value of cookie, set cookie), authentication and other information. It is not necessary to store


console to see the key and value of cookies? You can see it, but you can't take it out. It's possible that cookies's httpOnly is caused by true

.
Menu