laravel passport: Request user() returning null outside auth:api middleware, and inside returning user object

后端 未结 2 687
挽巷
挽巷 2020-12-09 13:06

When I am tring to get loggedin user details using auth:api middleware, it returns user object with details in my controller function.

api.php (with auth:api         


        
2条回答
  •  自闭症患者
    2020-12-09 13:57

    The auth middleware is the one returning the user. auth:api just indicates to use the API guard. In the source code of laravel, the file vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php line 62, the function shouldUse is the one setting the Auth::user() object. Check out also vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php shouldUse function

提交回复
热议问题