1

我正在使用 laravel/fortify 并尝试使用 HTTP 客户端请求进行身份验证

public function boot()
{
    Fortify::loginView(function () {
        return view('auth.login');
    });
    Fortify::authenticateUsing(function (Request $request) {
        $response = Http::withHeaders([
            'content-type' => 'application/json',
            'Accept' =>'application/json',
        ])->post('http://127.0.0.1:8001/v1/login', [
            'email' => $request->email,
            'password' => $request->password
        ]);
        if($response->ok()) {
            //Session::put('token',$response['access_token']);
            $data = $response->json();
            return $data;
        }

});

但我收到错误,错误是:

TypeError
Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of 
Illuminate\Contracts\Auth\Authenticatable, array given, called in 
home/suraj/Documents/locaxapp/client/locux/source/clients/vendor/laravel/fortify/src/
Actions/AttemptToAuthenticate.php on line 77
4

1 回答 1

1

像这样返回用户实例

 Fortify::authenticateUsing(function (Request $request) {
            $response = Http::withHeaders([
                'content-type' => 'application/json',
                'Accept' =>'application/json',
            ])->post('http://127.0.0.1:8001/v1/login', [
                'email' => $request->email,
                'password' => $request->password
            ]);
            if($response->ok()) {
                //Session::put('token',$response['access_token']);
                $data = $response->json();
                return User::find($data->id);
            }

或者你作为官方文件说

Fortify::authenticateUsing(function (Request $request) {
    $user = User::where('email', $request->email)->first();

    if ($user &&
        Hash::check($request->password, $user->password)) {
        return $user;
    }
})

参考链接https://jetstream.laravel.com/1.x/features/authentication.html

于 2020-09-21T11:17:41.700 回答