search

Home  >  Q&A  >  body text

Laravel 9 JWT logout problem php-open-source-saver/jwt-auth

I tried using php-open-source-saver/jwt-auth via tutorial https://blog.logrocket.com/implementing-jwt-authentication-laravel-9/

It works fine but I have some issues when logging out.

Auth::logout();

When I log out and try to call my test method, it uses the old token.

class SubjectController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth:api');
    }

    public function show($id)
    {
        $subject = Subject::find($id);

        return response(json_encode($subject))
            ->header('Content-Type','application/json');
    }
}


P粉809110129P粉809110129352 days ago467

reply all(1)I'll reply

  • P粉638343995

    P粉6383439952023-12-13 00:27:35

    Check the documentation: https://laravel-jwt-auth .readthedocs.io/en/latest/auth-guard/

    logout()

    Log out the user - This will invalidate the current token and unprovision the authenticated user.

    auth()->logout();
    
    // Pass true to force the token to be blacklisted "forever"
    auth()->logout(true);

    reply
    0
  • Cancelreply