Ghost88
Ghost88

Reputation: 33

How can I use web's guard and api's guard both in laravel project?

I have a problem with authentication in laravel. I added jwt auth in my project, because i need an authentication with token, but to use it I have to change default's guard in file "auth.php"

'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ], 

And here there is a problem, because if I change default's guard from 'web' to 'api' login route doesn't work anymore.

How can I solve this problem?

Thank you all.

Upvotes: 0

Views: 701

Answers (1)

dahalsaur
dahalsaur

Reputation: 11

To use both, change the api driver from 'token' to 'jwt' in auth guards. Leave defaults to as it is.

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

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

Upvotes: 1

Related Questions