Laravel JWT Auth get user on Login

后端 未结 9 2474
迷失自我
迷失自我 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条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 22:10

    It works fine for me (laravel 5.7) U must post token to me function and will return user use Tymon\JWTAuth\Facades\JWTAuth;

    public function me(Request $request)
    {
        $user = JWTAuth::user();
        if (count((array)$user) > 0) {
            return response()->json(['status' => 'success', 'user' => $user]);
        } else {
            return response()->json(['status' => 'fail'], 401);
        }
    }
    

提交回复
热议问题