令牌没有提供laravel 5.5

时间:2018-01-16 13:55:43

标签: php laravel

我正在使用jwt-auth进行apis身份验证,但我在尝试注册用户API并在注册用户后登录时不知道我在哪里出错:

我的注册码:

$fieldsValidation = [

    'name' => 'required',
    'email' => 'required|email',
    'password' => 'required',
    'c_password' => 'required|same:password',
];
$validator = Validator::make($request->all(), $fieldsValidation);
if ($validator->fails()) {
    $resultArray = [
        'status' => 0,
        'message' => $validator->errors()->first(),
        'dataArray' => []
    ];
} else {
    $user = $this->user->registerUser();
    $credentials = $request->only('email', 'password');
    $token = $this->getToken($credentials);
    if (strstr($token, 'status')) {
        return $token;
    }
    $user->token = $token;
    $resultArray = ['status' => 1, 'message' => 'User registered Successfully!', 'dataArray' => $user];
}
return Response::json($resultArray, 200);

我的登录代码:

$credentials = $request->only('username', 'password');
           $token = $this->getToken($credentials);
if (strstr($token, 'status')) {
    return $token;
}
$user = Auth::user();
$user->token = $token;
$resultArray = ['status' => 1, 'message' => 'User Logged-in Successfully!', 'dataArray' => $user];
return Response::json($resultArray, 200);

我的获取令牌功能

try {
    // verify the credentials and create a token for the user
    if (!$token = JWTAuth::attempt($credentials)) {
        $resultArray = ['status' => 0, 'message' => 'Invalid credentials!', 'dataArray' => []];
        return Response::json($resultArray, 200);
    }
} catch (JWTException $e) {
    // something went wrong
    $resultArray = ['status' => 0, 'message' => 'could not create token!', 'dataArray' => []];
    return Response::json($resultArray, 200);
}

return $token;

错误是我得到令牌未提供。我坚持我的问​​题任何帮助将不胜感激。

0 个答案:

没有答案