Get authenticated user with Laravel Passport and grant password

久未见 提交于 2019-11-30 11:28:24

You forgot the appropriate middleware.

Route::get('/user', function(Request $request) {
    return Auth::user();
})->middleware('auth:api');

The authentication flow is not fired when you don't mention the auth middleware. That's why you get null.

I had the same problem with you. And i solved it after I manually defined the auth guard.

Route::get('/user', function (Request $request) {
  return auth()->guard('api')->user();
});

You need to pass the Access token back with every request. Please check the documentation for this part here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!