Search code examples
laravellaravel-8laravel-sanctum

Argument 2 passed to Illuminate\\Auth\\SessionGuard::__construct() must implement interface Illuminate\\Contracts\\Auth\\UserProvider


This is my auth.php file


return [


    'defaults' => [
        'guard' => 'salon_emp',
        // 'passwords' => 'users',
    ],


    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'salon_emp' => [
            'driver' => 'jwt',
            'provider' => 'salon_emp'
        ],

        'app' => [
            'driver' => 'session',
            'provider' => 'client'
        ]
    ],
    'providers' => [
        'salon_emp' => [
            'driver' => 'eloquent',
            'model' => SalonEmployee::class,
        ],
        'client' => [
            'driver' => 'eloquent',
            'model' => Client::class
        ]
    ],

This is my login function in my LoginController

public function login(LoginRequest $request)
    {
        if (auth('app')->attempt($request->validated())) {
            auth('app')->user()->tokens()->delete();
            return apiResponse([
                'message' => 'Login successful!',
                'token' => auth('app')->user()->createToken(auth('app')->user()->name)->plainTextToken
            ]);
        } else {
            return apiResponse([
                'message' => 'Login not successful!',
            ], Response::HTTP_UNAUTHORIZED);
        }
    }

I am also using sanctum for authentication in my routes file i am using the auth:sanctum middleware to secure my routs, for example:

Route::get('/test',function ()
{
    dd('ss');
})->middleware('auth:sanctum');

how ever i get this error whenever i try to access it

Argument 2 passed to Illuminate\\Auth\\SessionGuard::__construct() must implement interface Illuminate\\Contracts\\Auth\\UserProvider, null given, called in \vendor\\laravel\\framework\\src\\Illuminate\\Auth\\AuthManager.php on line 128",

i have tried changing providers and drivers but no luck


Solution

  • I added this line to sanctum.php

    'guard' => 'app'

    and it worked fine