• <legend id='liO7T'><style id='liO7T'><dir id='liO7T'><q id='liO7T'></q></dir></style></legend>

      <tfoot id='liO7T'></tfoot>
        • <bdo id='liO7T'></bdo><ul id='liO7T'></ul>
        <i id='liO7T'><tr id='liO7T'><dt id='liO7T'><q id='liO7T'><span id='liO7T'><b id='liO7T'><form id='liO7T'><ins id='liO7T'></ins><ul id='liO7T'></ul><sub id='liO7T'></sub></form><legend id='liO7T'></legend><bdo id='liO7T'><pre id='liO7T'><center id='liO7T'></center></pre></bdo></b><th id='liO7T'></th></span></q></dt></tr></i><div id='liO7T'><tfoot id='liO7T'></tfoot><dl id='liO7T'><fieldset id='liO7T'></fieldset></dl></div>
      1. <small id='liO7T'></small><noframes id='liO7T'>

        Laravel JWT Auth 在登录时获取用户

        时间:2023-12-01

        <small id='CiJsm'></small><noframes id='CiJsm'>

          <tbody id='CiJsm'></tbody>
      2. <i id='CiJsm'><tr id='CiJsm'><dt id='CiJsm'><q id='CiJsm'><span id='CiJsm'><b id='CiJsm'><form id='CiJsm'><ins id='CiJsm'></ins><ul id='CiJsm'></ul><sub id='CiJsm'></sub></form><legend id='CiJsm'></legend><bdo id='CiJsm'><pre id='CiJsm'><center id='CiJsm'></center></pre></bdo></b><th id='CiJsm'></th></span></q></dt></tr></i><div id='CiJsm'><tfoot id='CiJsm'></tfoot><dl id='CiJsm'><fieldset id='CiJsm'></fieldset></dl></div>

        <legend id='CiJsm'><style id='CiJsm'><dir id='CiJsm'><q id='CiJsm'></q></dir></style></legend>
      3. <tfoot id='CiJsm'></tfoot>

                  <bdo id='CiJsm'></bdo><ul id='CiJsm'></ul>

                  本文介绍了Laravel JWT Auth 在登录时获取用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否可以使用 https://github.com/tymondesigns/jwt-auth获取当前用户?因为现在我只能生成一个令牌(当用户登录时).

                  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).

                  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'));
                  }
                  

                  推荐答案

                  可以获取登录的用户数据.

                  You can get logged user data.

                  $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;
                  

                  这篇关于Laravel JWT Auth 在登录时获取用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使 JWT 令牌 PHP 无效 下一篇:使用 JWT Laravel 5 进行身份验证,无需密码

                  相关文章

                  • <bdo id='OITPo'></bdo><ul id='OITPo'></ul>

                      <small id='OITPo'></small><noframes id='OITPo'>

                      <i id='OITPo'><tr id='OITPo'><dt id='OITPo'><q id='OITPo'><span id='OITPo'><b id='OITPo'><form id='OITPo'><ins id='OITPo'></ins><ul id='OITPo'></ul><sub id='OITPo'></sub></form><legend id='OITPo'></legend><bdo id='OITPo'><pre id='OITPo'><center id='OITPo'></center></pre></bdo></b><th id='OITPo'></th></span></q></dt></tr></i><div id='OITPo'><tfoot id='OITPo'></tfoot><dl id='OITPo'><fieldset id='OITPo'></fieldset></dl></div>
                    1. <legend id='OITPo'><style id='OITPo'><dir id='OITPo'><q id='OITPo'></q></dir></style></legend>

                      <tfoot id='OITPo'></tfoot>