【问题标题】:Laravel JWTAuth::encode , JWTAuth::attemp , JWTAuth::fromUser, unable to create a token, and throwing errorLaravel JWTAuth::encode , JWTAuth::attemp , JWTAuth::fromUser ,无法创建令牌,并抛出错误
【发布时间】:2016-08-08 15:02:31
【问题描述】:

Laravel JWTAuth::encode , JWTAuth::attemp , JWTAuth::fromUser ,无法创建令牌,并抛出错误

这就是我得到的全部回复,

Error Response Image a

Error Response Image b

routes.php中的登录路由是这样的:

Route::post('auth/login','authController@login');

而authController.php中的登录功能是这样的:

    function login(Request $request){

    $user = User::where('email', '=',$request['email'])
        ->first(['first_name', 'last_name', 'email', 'id', 'hashed_password']);
    // if email and password is wrong
    if(count($user) <= 0 )
            return response(["success"=>false,"message"=>"Authentication failed, wrong credentials"],401);
        //sendResponse(false, "Authentication failed, wrong credentials", null, 401);
    if (!Hash::check($request['password'], $user['hashed_password']))
    {
        return response(["success"=>false,"message"=>"Authentication failed, wrong credentials"],401);
    }
    try{
        // attemp to verify the credentials and create a token for the user
        $payload = JWTFactory::make($user['original']);
        $token = JWTAuth::encode($payload);
        $user['jwt'] = $token;
        $user->save();
    }
    catch(Exception $e){
        // something went wrong while creating token or updating user
        return response(["success"=>false,"message"=>"There's something wrong, we will get back to you soon."],400);
    }

    $content['message'] = "Successfully Login";
    $content['success'] = true;
    $content['token'] =  $user['jwt'];
    $content['data']['first_name'] = $user['first_name'];
    $content['data']['last_name'] = $user['last_name'];
    $content['data']['email'] = $user['email'];
    return response($content,200)
        ->header('Content-Type', "application/json");

}

我被这个错误困扰了两天,仍然无法找到解决方案。尝试通过在我的 php.ini 中添加以下行来最大化嵌套级别

;xdebug.max_nesting_level=1000

但是没有用。

请帮忙。

【问题讨论】:

    标签: laravel authentication token jwt


    【解决方案1】:

    查看您的错误消息,它仍然在默认xdebug.max_nesting_level上起作用。

    根据您所显示的,您在 php.ini 文件中进行了更改 - 您已经更新了您的 xdebug.max_nesting_level,但将其注释掉以使其不会产生任何影响。

    您需要通过删除它之前的; 来取消注释它,使其看起来像这样:

    xdebug.max_nesting_level=1000

    然后重启你的服务使其生效。

    【讨论】:

      猜你喜欢
      • 2017-11-05
      • 2016-08-23
      • 2018-11-23
      • 2016-09-01
      • 2018-12-27
      • 2017-10-17
      • 2016-04-23
      • 2017-01-29
      • 1970-01-01
      相关资源
      最近更新 更多