You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Route::middleware('auth:api')->get('/user', function (Request$request) {
$user = $request->user();
$token = $user->token();
// expired token still passes the auth:api middleware// so we need to check it manuallyif ($token->expires_at < Illuminate\Support\Carbon::now()) {
// revoke the token$token->revoke(); // ⮑ true, $token->revoked will be set to 1// or, delete the token$token->delete(); // ⮑ true, token info will be removed from dbreturnresponse()->json([
'error' => 'Unauthenticated.'
], 401);
}
return$user;
});