Monday, 6 December 2021

Laravel InvalidArgumentException: Auth guard [api] is not defined

 Errors:

Auth guard driver [api] is not defined.

 Lumen 5.4 - Auth guard driver [api] is not defined.

InvalidArgumentException: Auth guard [api] is not defined. 



Solution:

Basically, the API guard driver is missing from the auth file. First, we need to set up the API guard.

Open file config/auth.php

We can see default web guard is already defined.


Here we need to define API guard. Add the following code to the guard's array.

 'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],



If you are using any package, then update the API index accordingly.

For passport, package add 

'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
For jwt package add 
'api' => [
            'driver' => 'jwt',
            'provider' => 'users',
        ],


After adding or updating the API guard driver, please run composer update using the following command.

composer update.


That's all we need to do. If you have any questions or suggestions please do share them in the comment section

No comments:

Post a Comment

Laravel csrf token mismatch for ajax post request

Error "CSRF Token Mismatch" commonly occurs if tokens do not match in both sessions and sent , and received requests.CSRF token he...