【发布时间】:2016-08-08 15:02:31
【问题描述】:
Laravel JWTAuth::encode , JWTAuth::attemp , JWTAuth::fromUser ,无法创建令牌,并抛出错误
这就是我得到的全部回复,
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