Search code examples
laravellumenlaravel-passport

Auth driver [api] for guard [api] is not defined


When I login the user in laravel lumen passport project and testing on postman the error is coming

Auth driver [api] for guard [api] is not defined

my login fuction is `

 public function login(Request $request)
    {
        
        $login_credentials=[
            'email'=>$request->email,
            'password'=>$request->password,
        ];
        if(auth()->attempt($login_credentials)){
        
            $user= auth()->user();
         
            return response()->json(['user' => $user], 200);
        }
        else{
            //wrong login credentials, return, user not authorised to our system, return error code 401
            return response()->json(['error' => 'UnAuthorised Access'], 401);
        }
    }

and the route is

$router->group(
    ['prefix' => 'v1/api',
    'middleware' => 'client'],
    function () use ($router) {
        $router->post('/register','UserController@register');
        $router->post('/login','UserController@login');
});

my boostrap/config/auth.php file is

return [
    'defaults' => [
        'guard' => 'api',
        'passwords' => 'users',
    ],
'guards' => [
        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
            'hash' => true,
        ],
    ],
'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => \App\Models\User::class
        ]
    ]
];

` I am trying to login the user i want to login the user but the error is coming

Auth driver [api] for guard [api] is not defined

i dont know what to do for this error . And from where the error is coming . If anyone can help please reply

thanks in advance,


Solution

  • It looks like, you have placed the auth.php file in the wrong directory. It should not be in the bootstrap directory it should be in the root directory

    your-project/config/auth.php