Can you show your User model ?
Nov 3, 2021
20
Level 1
Fortify: Authenticate using API JSON Response
I am using Fortify to validate a user via a API, which returns a json array of user data.
{
"userid": "1",
"twoFactorEnabled": "false",
"name": "Test User"
}
Here is what I am doing within the authenticate using method within Fortify Boot.
Fortify::authenticateUsing(function (Request $request) {
if($api->validate($request->username, $request->passwprd)) {
return $api->find($request->username);
}
});
I am doing the above to validate whether or not the username, and password is correct.
Then I am returning the above JSON array if that user is validated from the array.
However, when I do this I receive the following Error from the frontend.
Illuminate\Auth\SessionGuard::login(): Argument #1 ($user) must be of type Illuminate\Contracts\Auth\Authenticatable, array given, called in /home/-/my..io/vendor/laravel/fortify/src/Actions/AttemptToAuthenticate.php on line 80
I have got no Database access at all, this must all be done via the data response from API.
<?php
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* @var string[]
*/
protected $fillable = [
'id',
'twoFactorEnabled',
'name'
];
}
Please or to participate in this conversation.