php – Laravel JWT Auth让用户登录
发布时间:2020-12-14 19:46:58 所属栏目:大数据 来源:网络整理
导读:有可能用 https://github.com/tymondesigns/jwt-auth 获得当前用户?因为现在我只能生成一个令牌(当用户登录时). public function login(Request $request){ $credentials = $request-only('email','password'); try { if (! $token = JWTAuth::attempt($cre
有可能用
https://github.com/tymondesigns/jwt-auth
获得当前用户?因为现在我只能生成一个令牌(当用户登录时). public function login(Request $request) { $credentials = $request->only('email','password'); try { if (! $token = JWTAuth::attempt($credentials)) { return response()->json(['error' => 'invalid_credentials'],401); } } catch (TymonJWTAuthExceptionsJWTException $e) { return response()->json(['error' => 'could_not_create_token'],500); } return response()->json(compact('token')); }
您可以获取记录的用户数据.
$credentials = $request->only('code','password','mobile'); try { // verify the credentials and create a token for the user if (! $token = JWTAuth::attempt($credentials)) { return response()->json(['error' => 'invalid_credentials'],401); } } catch (JWTException $e) { // something went wrong return response()->json(['error' => 'could_not_create_token'],500); } $currentUser = Auth::user(); print_r($currentUser);exit; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |