Now I enter my account password, the browser sends a request, and the token is returned successfully;
What I want to ask is: Should I put this token in a cookie or in localStorage?
Also, how to deal with login interception on other pages?
Is it necessary to determine if there is a token in the cookie or localStorage and then release it?
(If so, others can just create a token and let it go)
And how to use the successfully returned timeout period? Is it placed in the cookie?
Or is my thinking wrong?
After the user authentication is successful, the
The login interception of thetoken
值,前端一般存在localStorage
里。每次发出请求的时候,把该
token
放在请求头即可。下面以
axios
returned by the server is as an example:page takes
vue.js
的vue-router
as an example:Also
token
值一般是很难伪造的,因为每次请求都会向后端去验证该token
the validity of the value.It is recommended to use setCookie in the request returned by the server to set the token, and set it to httpOnly. Bring cookies in subsequent requests, and then determine the status based on the server's callback.