jwt-auth
jwt-auth copied to clipboard
Invalidate expired token (but renewable)
Subject of the issue
Invalidating a token gives token expired exception
Your environment
| Q | A |
|---|---|
| Bug? | no (?) |
| New Feature? | yes |
| Framework | Laravel |
| Framework version | 8.47 |
| Package version | 1.0.2 |
| PHP version | 8.0.1 |
Steps to reproduce
Try to invalidate an expired token, with:
auth()->invalidate()
Expected behaviour
Token get blacklisted
Actual behaviour
TokenExpired exception thrown
thanks!
Did you find a solution ? I'm having the same problem
Hi, no. I found that refreshing the token invalidates the previous one. So I create and drop a new one: auth()->refresh();
If you have already created a new token, this will invalidate the new one.
Hi, no. I found that refreshing the token invalidates the previous one. So I create and drop a new one:
auth()->refresh();If you have already created a new token, this will invalidate the new one.
Thank you @dhcmega This is my final code
$old_token = $user->jwt_token;
try {
JWTAuth::setToken($old_token)->invalidate();
} catch (TokenExpiredException $e) {
// do nothing
}
Oh, ok, it throws an exception but also invalidates the token? Thanks for sharing.