Search code examples
phplaraveljwtdingo-api

Laravel JWT Auth Returning False


I have followed the tutorial below but when I get the current user it always returns false. I am able to sign in and get my token in postman. I then create the url and hit send. However the following function always returns false.

$currentUser = JWTAuth::parseToken()->authenticate();
dd(currentUser)

https://www.sitepoint.com/how-to-build-an-api-only-jwt-powered-laravel-app/

Update When I run the below code I get the token value.

$token = JWTAuth::getToken();
JWTAuth::setToken($token);

The code fails at the following point

if (! $user = JWTAuth::parseToken()->authenticate()) {
    return response()->json(['user_not_found'], 404);
}

Solution

  • Below is the answer that solved my problem. I was using user_id as opposed to id. I changed this in the jwt config file.

    Tymon JWT user_not_found - Laravel 5.1

    More on this below

    https://github.com/tymondesigns/jwt-auth/issues/155