JWT给出user_not_found错误

时间:2016-12-19 04:35:28

标签: php authentication jwt

我收到了user_not_found错误,我认为我的令牌生成有问题。我正在使用mongodb,我有一个用户集合和一个authInfo集合。 authInfo包含用户标识和散列以及其他与auth相关的内容。我刚刚添加了auth集合,当我只是将所有内容存储在用户集合中时,我使用了令牌,因此我认为使用与用户集合不同的集合存在一些问题

登录功能:

script.setAttribute('async', false);

generateToken函数:

public function checkLogin(Request $request) {
  $credentials = $request->json()->all();

  $authInfo = AuthInfo::where('email', $credentials['email'])->first();

  if (!is_null($authInfo) and Hash::check($credentials['password'], $authInfo->hash)) {
    $token = $this->generateToken($authInfo->user_id);

    return Response::json(['token' => $token->get()]);
  }

  return Response::json(['error' => 'invalid_credentials'], 401);
}

我的jwt.php设置

public function generateToken($userId)
{
    $payload = JWTFactory::make(['id' => $userId]);
    $token = JWTAuth::encode($payload);
    return $token;
}

0 个答案:

没有答案