how to destroy jwt token,use JWTAuth::invalidate($token) not work
| Q | A
| ----------------- | ---
| Bug? | no
| New Feature? | no
| Framework | Laravel
| Framework version | 5.7
| Package version | 1.0.0-rc.3
| PHP version | 7.2.12
JWTAuth::invalidate function need the parameter is $forceForever not the token
/**
* Invalidate a token (add it to the blacklist).
*
* @param bool $forceForever
*
* @return $this
*/
public function invalidate($forceForever = false)
{
$this->requireToken();
$this->manager->invalidate($this->token, $forceForever);
return $this;
}
now,I have a old token need to destroy it when user login,so which function can I use? thx!
@hhxiaohei Have a look at these docs.
https://jwt-auth.readthedocs.io/en/develop/auth-guard/#invalidate
You don't pass the token, just the param for forceForever.
if ever you need to invalidate a different token, for example you are tracking a list of tokens in a database and you want to invalidate them..
\JWTAuth::manager()->invalidate(new \Tymon\JWTAuth\Token($tokenString), $forceForever = false);
Why didn’t you just mention that it is easier to invalidate with the auth helper, in the following way:
auth()->invalidate(true)
In my case my guard is called store_user so
auth(“store_users”)->invalidate(true)
The true will forever invalidate the token
Why didn’t you just mention that it is easier to invalidate with the auth helper, in the following way:
auth()->invalidate(true)
In my case my guard is called store_user so
auth(“store_users”)->invalidate(true)
The true will forever invalidate the token
@ajcastro is right with his solution, because auth()->invalidate($token) for few doesn't work.
if ever you need to invalidate a different token, for example you are tracking a list of tokens in a database and you want to invalidate them..
\JWTAuth::manager()->invalidate(new \Tymon\JWTAuth\Token($tokenString), $forceForever = false);
Thanks, it worked for me as compare to auth()->invalidate($token)
Most helpful comment
if ever you need to invalidate a different token, for example you are tracking a list of tokens in a database and you want to invalidate them..