Laravel JWT Auth get user on Login

后端 未结 9 2475
迷失自我
迷失自我 2021-02-01 21:16

Is it possible with https://github.com/tymondesigns/jwt-auth to get the current user? Because right now I can only generate a token (when a user sign in).

9条回答
  •  旧时难觅i
    2021-02-01 21:52

    In Laravel 7.2 if none of the above works use like this to retrive the user:

    $credentials = request(['email', 'password']);
    
    if (! $token = auth('api')->attempt($credentials)) {
            return response()->json(['error' => 'Unauthorized'], 401);
    }  
        
    $user = auth('api')->user();
        
    dd($user);
    

提交回复
热议问题