A
A
ashfedor2021-08-17 15:19:21
Laravel
ashfedor, 2021-08-17 15:19:21

How to make both web and api authentication in Laravel?

There is a control panel written in Laravel c Blade.
It is necessary that a separate crm is connected to it, it will be either on a separate domain or subdomain, it works on NUXT I use jwt-auth.
Now the entrance to the panel is through the usual web login form.
In auth.php is

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

But with the web defender, user login via api does not work.
Of course I switch to api
'defaults' => [
        'guard' => 'api',
        'passwords' => 'users',
    ],

Authentication via the web stops working and I can't get into the admin panel.
Surely there is a solution to the problem, can anyone tell me?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin B., 2021-08-19
@Kostik_1993

Passport has Middleware for this case. Likewise in Sanctum

B
Barmunk, 2021-08-19
@Barmunk

jwt-auth has nothing to do with this. You leave "web" by default, and use an explicit guard call in all api methods, for example: auth()->guard('api'), the JWTAuth facade also helps out, it automatically switches the context of Auth::user().
https://github.com/tymondesigns/jwt-auth/issues/1746

I
inFureal, 2021-08-19
@inFureal

tyts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question