0

我有AuthController

public function register(Request $request)
{
    $user = UserSistem::create([
        'username' => $request->username,
        'nama' => $request->nama,
        'email' => $request->email,
        'password_secret' => bcrypt($request->password)
    ]);

    $token = auth()->login($user);

    return $this->respondWithToken($token);
}

public function login(Request $request)
{
    $credentials = $request->only(['email', 'password']);

    if (!$token = auth()->attempt($credentials)) {
        return response()->json(['error' => 'Unauthorized'], 401);
    }

    return $this->respondWithToken($token);
}

protected function respondWithToken($token)
{
    return response()->json([
        'access_token' => $token,
        'token_type' => 'bearer'
    ]);
}

registerfunction 是工作,但不是 for login,我应该使用passwordcolumn 而不是password_secretin registerfunction,因为我尝试使用passwordcolumn 并且工作正常吗?

如何password_secret在函数中使用有效载荷上的列register

4

1 回答 1

0

您正在使用 JWT,然后将凭据传递给 JWT 对象

public function login(Request $request)
{
  $credentials = $request->only(['email', 'password']);
   try {
    if (!$token =  JWTAuth::attempt($credentials)) {
    return response()->json(['error' => 'Unauthorized'], 401);

} catch (JWTException $e) {
            // something went wrong
return response()->json(['error' => 'could_not_create_token'], 500);
        }
}

return $this->respondWithToken($token);
}
于 2018-09-21T05:37:29.723 回答