3

i have an API to authenticate using a username,password,role. the result would be like this in json

{
    "success": true,
    "message": "Welcome !",
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2FwaS5hbGhpa21haGJvZ29yLm9yZy92MS9tb2JpbGUvYXV0aC9sb2dpbiIsImlhdCI6MTUzODAxOTg2NCwiZXhwIjoxNTM4MTA2MjY0LCJuYmYiOjE1MzgwMTk4NjQsImp0aSI6IjZuTlNLSUdFeDdaT1l2bTkiLCJzdWIiOjY1fQ.N0rtAsA2cTWfsYulRsrdkiso3dXHe_7W16BSYrdVwa8",
    "data": [
        {
            "id": 65,
            "username": "0110-04-005",
            "email": "yourmail@gmail.com",
        }
    ]
}

and also the guzzle should be like this

$requestResponse = $client->request('POST',$productionUrl,[
                        'auth' => ['username','password'],
                        'form_params' => [
                            'username' => $request->nis,
                            'password' => $request->sandi,
                            'role' => 'santri'
                        ],
                        'cookies' => $cookieJar,
                        'content-type' => 'application/json',
                        'connect_timeout' => 3.14
                    ]);
            $res = json_decode($requestResponse->getBody(),true);

and everytime i use auth to log in with this method of authentication Auth::login($res) or auth()->login($res), it replies the error like this

Type error: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, array given, called in /Applications/XAMPP/xamppfiles/htdocs/my.alhikmahbogor/core/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php on line 294

how do i login with that methode of laravel authentications using guzzle http ?

Abdan Syakuro
  • 1,034
  • 2
  • 12
  • 26

0 Answers0