#php #laravel #httpclient #fortify #laravel-8
#php #laravel #httpclient #укрепление #laravel-8
Вопрос:
Я использую 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 IlluminateAuthSessionGuard::login() must be an instance of
IlluminateContractsAuthAuthenticatable, array given, called in
home/suraj/Documents/locaxapp/client/locux/source/clients/vendor/laravel/fortify/src/
Actions/AttemptToAuthenticate.php on line 77
Ответ №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 amp;amp;
Hash::check($request->password, $user->password)) {
return $user;
}
})
ссылка на ссылку https://jetstream.laravel.com/1.x/features/authentication.html
Комментарии:
1. @sunfarmahulla попробуйте мое решение, которое я добавил