Jwt-auth: how to destroy jwt token,use JWTAuth::invalidate($token) not work

Created on 18 Jun 2019  Â·  5Comments  Â·  Source: tymondesigns/jwt-auth

Subject of the issue

how to destroy jwt token,use JWTAuth::invalidate($token) not work

Your environment

| 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

Steps to reproduce

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!

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..

\JWTAuth::manager()->invalidate(new \Tymon\JWTAuth\Token($tokenString), $forceForever = false);

All 5 comments

@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)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

phamduong picture phamduong  Â·  3Comments

lloy0076 picture lloy0076  Â·  3Comments

lbottoni picture lbottoni  Â·  3Comments

therealmjk picture therealmjk  Â·  3Comments

aofdev picture aofdev  Â·  3Comments