Token problem of vue-cli front-end separation project

use vue-cli for front and back end separate development. For example, the front end performs login operation, and the back end returns token:

.
return response()->json([
            "access_token" => $tokenResult->accessToken,
            "token_type" => "Bearer",
            "expires_at" => Carbon::parse(
                $tokenResult->token->expires_at
            )->toDateTimeString()
        ]);


question:
1. After the frontend gets the token returned by the backend, do you need to bring the token with you every time you initiate a request?
2. Because token is about to expire, does every method in the backend return token??

May.29,2021

  1. if the backend uses this to check the expiration time, it is the
  2. that needs to be brought. It is true that the
  3. token will expire, but after each request, the backend should reset the validity of the token to the maximum. You don't need to return token every time. The new token, is returned only when it expires. At this time, the front end needs to update the token
  4. .

  1. is
  2. No, the front end always has the original token , wait for the backend to inform you that it expires, then renew through refresh_token , or re-jump to log in.

the project on my side is that after login, each request will bring the token returned by login. After the
token expires, the specified status code is returned, forcing the jump login.

Menu