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

时间:2016-04-16 17:39:07

标签: laravel authentication token jwt

Laravel JWTAuth :: encode,JWTAuth :: attempt,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

但它没有用。

请帮助。

1 个答案:

答案 0 :(得分:0)

查看您的错误消息,它仍然采用默认的xdebug.max_nesting_level

根据您在php.ini文件中显示的更改内容 - 您已更新了xdebug.max_nesting_level但已将其注释掉,以便它无法接受任何操作影响。

您需要删除之前的;取消注释,以便它看起来像这样:

xdebug.max_nesting_level=1000

然后重新启动服务以使其生效。