Home > front end >  The separation of front and rear end the session log in problem
The separation of front and rear end the session log in problem

Time:09-17

When the backend authentication username and password match generated when a session, containing userID, I want to ask front how to obtain the login status, jump to need to log in to access the page, and how to get into the session at the front of userID, check a lot of information, are very fuzzy, hope to have bosses can be solved

CodePudding user response:

Forgot to say, the front is the vue framework, the backend is springboot

CodePudding user response:

Web log=& gt; Login request API=& gt; API returns the session/error message=& gt; Web caching session cookies and jump to login to access the page, each request API pass session to API test current state
Refresh the page of the web from a cookie session, the session when the parameter passed to the API request API inspection, failure to return to the login page, success continue to access the page,

CodePudding user response:

Request response will back sessionStorage. SetItem (" userID ", userID); Stored in the session, if you need to login state can jump page, you can use axios request interception, request put the head or the login userId and status information what you need, request before judging whether satisfy the condition that you need, does not meet the jump to the login page, after login to enter the interface of need to log in to
Before I also wrote an article on the axios packaging with a request to intercept, you can refer to take a look at https://blog.csdn.net/weixin_45471782/article/details/100225111

CodePudding user response:

Request after using sessionStorage. SetItem to save data, and then join in the request method of encapsulation request interception, through the sessionStorage. The getItem method to collect data, have value to execute the request, did not return to the login page, also can be also judged by routing guard login status,
Request to intercept intercept and routing guard how to use baidu, routing guard written I have written in the article, can go to have a look at
  •  Tags:  
  • Ajax
  • Related