Search code examples
laravellaravel-passport

Log all authentication errors Laravel (nova)


I am building an api and my post request return the following message

{"message":"Unauthenticated."}

This messsage is quite unclear. I would like to log more info about the Laravel passport authentication attempts.

I would like to log them to

/storage/logs

Question:
Is it possible to log detailed Auth error messages into the storage log folder?


Solution

  • In your Laravel exception handler file create a custom handler for the exception that is being thrown that logs more information. On the OAuthServerException you can call getHint() to get a more specific error. References :

    I hope Reading following laravel passport github issues will help you

    https://github.com/laravel/passport/issues/403

    https://github.com/laravel/passport/issues/289