1

I have a Laravel 12 with 2 guards "web" and "admin", the admin guard has its own user table "admins" (privacy concerns).

We have 2 Models "User" and "Admin", the Admin Model starts like:

{
 use HasFactory, HasRoles, Notifiable, SoftDeletes, TwoFactorAuthenticatable;
 protected string $guard_name = 'admin';
 protected $table = 'admins';
--snip--

both are configured in config/auth.php like:

'guards' => [
 'web' => [
 'driver' => 'session',
 'provider' => 'users',
 ],
 'admin' => [
 'driver' => 'session',
 'provider' => 'admin',
 ],
],
'providers' => [
 'users' => [
 'driver' => 'eloquent',
 'model' => App\Models\User::class,
 ],
 'admin' => [
 'driver' => 'eloquent',
 'model' => App\Models\Admin::class,
 ],
'passwords' => [
 'users' => [
 'provider' => 'users',
 'table' => 'password_reset_tokens',
 'expire' => 60,
 'throttle' => 60,
 ],
 'admin' => [
 'provider' => 'admin',
 'table' => 'password_reset_tokens_admin',
 'expire' => 60,
 'throttle' => 60,
 ],
],

Everything is working for the web guard. I can register, login and see my profile with both usergroups/guards.

What does NOT work for admin guard is Fortify's 2FA "confirm password" route.

When i click on "2FA Authentication" as "admin", i get redirected to the "Confirm Password" route of the wrong guard "web", I am not logged in with "web", so I get redirected to "web" Login.

It works for the admin guard, when i change register() in FortifyServiceProvider.php like this:

config(['fortify.guard' => 'admin']);
config(['fortify.passwords' => 'admins']);
config(['fortify.home' => '/admin/dashboard']);

I tried to change the config values based on the session, but there is no session yet on ServiceProvider level, the session will only get initialized later in the framework.

Someone has a solution for that?

asked 17 hours ago

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.