始终未授权Jwt-auth Laravel

时间:2018-09-21 03:38:01

标签: laravel jwt-auth

我有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'
    ]);
}

register函数有效,但不适用于login,我应该在password函数中使用password_secret列而不是register,因为我尝试使用password列工作正常吗?

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

1 个答案:

答案 0 :(得分:0)

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

class mainwindow(tk.Tk):
    #Initalize main window
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

       #use to shift frames
       ....
 if __name__ == "__main__":
    ...
    app = mainwindow()
    app.geometry("1920x1080")
    app.mainloop()