Laravel JWTAuth::encode , JWTAuth::attemp , JWTAuth::fromUser ,无法创建令牌,并抛出错误
Posted
技术标签:
【中文标题】Laravel JWTAuth::encode , JWTAuth::attemp , JWTAuth::fromUser ,无法创建令牌,并抛出错误【英文标题】:Laravel JWTAuth::encode , JWTAuth::attemp , JWTAuth::fromUser, unable to create a token, and throwing error 【发布时间】:2016-08-08 15:02:31 【问题描述】:这就是我得到的全部回复,
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】:查看您的错误消息,它仍然在默认xdebug.max_nesting_level
上起作用。
根据您所显示的,您在 php.ini
文件中进行了更改 - 您已经更新了您的 xdebug.max_nesting_level
,但将其注释掉以使其不会产生任何影响。
您需要通过删除它之前的;
来取消注释它,使其看起来像这样:
xdebug.max_nesting_level=1000
然后重启你的服务使其生效。
【讨论】:
以上是关于Laravel JWTAuth::encode , JWTAuth::attemp , JWTAuth::fromUser ,无法创建令牌,并抛出错误的主要内容,如果未能解决你的问题,请参考以下文章