I inherited a project with laravel jetstream v2.7 and need a middleware that goes to check if 2fa is enabled and if not redirect it to a view where you are forced to enable 2fa.
The middleware:
public function handle(Request $request, Closure $next): Response
{
if (is_null(Auth::user()->two_factor_secret)) {
return redirect(route('2fa'));
}
return $next($request);
}
and the view:
@if (Laravel\Fortify\Features::canManageTwoFactorAuthentication())
<div class="mt-10 sm:mt-0">
@livewire('profile.two-factor-authentication-form')
</div>
@endif
@if(auth()->user()->two_factor_secret)
<a href="dashboard" class="btn btn-lg btn-primary backmobile">Next</a>
@endif
and web.php:
// 2FA
Route::get('2fa', function () {
return view('auth1.2fa');
})->name('2fa');
// Go to dashboard if registration is completed
Route::group(['middleware' => ['registration_completed', 'verified', 'checkSuspendedUser','has2FaEnabled']], function () {
The problem is that clicking the button that should enable 2fa does not work. The same technique works in the custom profile settings view. Why?
I want to force 2fa enablement via middleware verification