The front and back ends separate the project, and the background token is refreshed. How does the front end know it is refreshed?

there are two related token, one is access_token , the other is refresh_token , there are two questions, please explain:

The function of

1, refresh_token is to see that access_token is about to expire, then access_token will be regenerated, so refresh_token how do you know access_token is about to expire?

2. access_token is generated when the front end logs in, which is marked as token_1. When the token_1 is about to expire, the backend refresh_token refreshes access_token , and then the token_2, is generated. So, how does the backend tell the front end the refreshed token_2 so that the front end can carry the new token_2?

?

does not have the expired front end to judge whether the token expires or not?
theoretically, if there is no web socket active push,
the process should call the API twice. If the access_token call fails, then the refresh_token call reacquires access_token, when the original interface


the back end pushes a TONKEN update data to the front end


when you initiate a http request. The browser will bring cookie by default, and the backend receives this request and reads the cookie, inside to check whether it is about to expire. If so, the server updates cookie, and appends it to response. Update cookie.


cookie


answer


if you only need to push the back end to the front end, try SSE


1.refresh token does not know, but the backend knows that when you send the request operation data, the token expires and the backend returns to you that you have no permission (or a custom error code indicates expiration). You take a look at the local error. I have token, so it seems that my token has expired?

2. Okay, what if it expires? when I logged in, I returned not only token but also refresh token, ah, just like what should I do when my Hong Kong and Macao pass expired? take the refresh token to the backend interface to renew the backend and give you a new token. Then I will bring this token. From then on, you can continue to request data

.
Menu