I’m about to add 2FA using Google Authenticator to my application but I have issues with adding Fortify.
My laravel project is years old, but I’m updating it to the newest versions. Right now I’m using laravel 11 (upgraded recently from 9).
Issue that I’m facing is somehow connected to middleware. I figured out that this code is causing troubles:
$twoFactorMiddleware = Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword')
? [config('fortify.auth_middleware', 'auth').':'.config('fortify.guard'), 'password.confirm']
: [config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')];
That is actually from Fortify routes.
So when I try to enable 2FA for user using their route:
Route::post(RoutePath::for('two-factor.enable', '/user/two-factor-authentication'), [TwoFactorAuthenticationController::class, 'store'])
->middleware($twoFactorMiddleware)
->name('two-factor.enable');
It is giving me an error “Illegal offset type” in file ‘vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php’. After removing ->middleware($twoFactorMiddleware) I don’t receive error anymore and 2FA secret is set properly.
AuthManger.php:
public function guard($name = null)
{
$name = $name ?: $this->getDefaultDriver();
return $this->guards[$name] ?? $this->guards[$name] = $this->resolve($name);
}
I tried reinstalling fortify and reinstalling everything from composer but it didn’t help. ALthough I did setup new laravel 11 project and everything worked just fine. I’ve lost hours on this issue and still nothing. Any help is much appreciated, thanks !