i want to add a page between two-factor-challenge. The user should get redirected to a setup page (This works) but when i choose the option i want, i get redirectet to my login page and not to the two-factor-challenge page. That is definted in the FortifyServiceProvider
I got a Middleware that checks if the user is logged in, when not redirect to the two-factor-challenge page.
public function handle(Request $request, Closure $next)
{
$user = $request->user();
// Benutzer nicht eingeloggt? Weiterleitung zum Login
if (!$user) {
return redirect()->route('login');
}
// 2FA nicht aktiviert? Weiterleitung zum nächsten Schritt
if (!$user->two_factor_enabled) {
return $next($request);
}
// Weiterleitung zur Two-Factor-Challenge
return redirect()->route('two-factor.challenge');
}
Route::get('/two-factor-challenge', [TwoFactorAuthenticatedSessionController::class, 'create'])
->name('two-factor.challenge');
public function setup2FAMethode(Request $request)
{
$request->validate([
'totp_methode' => 'in:totp,sms,email',
]);
if ($request->session()->get('two_factor_authenticated')) {
return redirect()->route('dashboard');
}
switch ($request->input('totp_methode')) {
case 'sms':
// Logik für SMS
return redirect()->route('two-factor.challenge');
case 'totp':
// Redirect auf die Two-Factor-Challenge-Seite
return redirect()->route('two-factor.challenge');
case 'email':
// Logik für E-Mail
return redirect()->route('two-factor.challenge');
default:
return redirect()->route('setup');
}
}
I tried to add a set a own route to the two-factor.challenge but than fortify doesnt triggeres the two-factor.login with the tokken. The Store function.