jwt refresh doesn't update custom claims

Viewed 339

This question has been asked many times, but decent solution couldn't be found.

I do this - $newToken = auth()->refresh();

in my custom claims, I have

 public function getJWTCustomClaims()
    {
        return [
            'is_verified' => $this->verified,
            'email' => $this->email,
            'role' => $this->getMainRole()->name
        ];
    }

Scenario - first, when I login, it returns me the jwt token. in that jwt token, I have is_verified , email, role set. Let's say is_verified was 0 at the time i got the token. Now, I changed it to 1 in database. NOw when I refrehs the token, as I showed you above, returned jwt token still has is_verified equal to 0, but it should have 1. Any idea how to fix it?

1 Answers

Try with $newToken = auth()->refresh(false, true);

Second parameter is "reset claims":

JWTGuard class - public function refresh($forceForever = false, $resetClaims = false)

Related