JWTAuth::user() returns null

  jwt, laravel, token

I am using Laravel 8 and JWTAuth package for the api requests, often the request throws error when trying to access user info with the following line:

JWTAuth::user()->id

The error: 500 Internal Server Error

ErrorException: Trying to get property 'id' of non-object ...

The only way I could resolve this, temporary however, is to refresh the token. I am wondering that if token is expired it should say token is expired, but seems something else is happening here, which I could not figure it out.

Appreciate any help!

Source: Laravel

Leave a Reply