Nov 9, 2024
0
Level 1
Question about grouping auth routes with email verification and 2FA
Hello, I have a question about the best way to create groups in middleware auth.
I use laravel 11 with breeze starter kit with volt components and have enabled email verification under user. I'm not sure if I need a second group and if they won't hinder each other, but in any case it works without anything going wrong. In the future I would like to integrate 2FA and I don't know exactly in which group I should put the middleware "2fa.enabled".
This is what it looks like at the moment:
// middleware('guest') Routes for Login, Registration ...
Route::middleware('guest')->group(function () {
Volt::route('register', 'pages.auth.register')
->name('register');
Volt::route('login', 'pages.auth.login')
->name('login');
Volt::route('forgot-password', 'pages.auth.forgot-password')
->name('password.request');
Volt::route('reset-password/{token}', 'pages.auth.reset-password')
->name('password.reset');
// Load Markdown-Files via Route
// if (Jetstream::hasTermsAndPrivacyPolicyFeature()) {
Route::get('/terms-of-service', [TermsOfServiceController::class, 'show'])->name('terms.show');
Route::get('/privacy-policy', [PrivacyPolicyController::class, 'show'])->name('policy.show');
// }
}); // middleware('guest')
// middleware('auth') Routes for all Backend Routes (Dashboard, ... later on for the Application)
Route::middleware('auth')->group(function () {
Volt::route('verify-email', 'pages.auth.verify-email')
->name('verification.notice');
Route::get('verify-email/{id}/{hash}', VerifyEmailController::class)
->middleware(['signed', 'throttle:6,1'])
->name('verification.verify');
Volt::route('confirm-password', 'pages.auth.confirm-password')
->name('password.confirm');
// middleware('verified') Routes nested inside middleware('auth')
// also for Backend Routes (Dashboard, ... later on for the Application)
// if in User model 'MustVerifyEmail' is activated, these routes request if the users email is verified
// if in User model 'MustVerifyEmail' is NOT activated, these routes uses only the middleware('auth') like above
// https://laravel.com/docs/11.x/verification
Route::middleware('verified')->group(function () {
Volt::route('dashboard', 'dashboard.dashboard')
// ->middleware(['verified'])
->name('dashboard');
Volt::route('profile', 'dashboard.profile.update-profile')
// ->middleware(['verified'])
->name('profile');
Volt::route('account', 'dashboard.account.account')
// ->middleware(['verified'])
->name('account');
// Route::view('/account', 'account')->name('account');
}); // middleware('verified')
}); // middleware('auth')
Please or to participate in this conversation.