feat: add optional email verification flow

This commit is contained in:
2026-03-19 23:15:07 +01:00
parent 1b9bf0efac
commit a096704b0b
3 changed files with 111 additions and 1 deletions

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\EmailVerificationRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
class EmailVerificationController extends Controller
{
public function __construct()
{
if (! config('auth-ui.features.email_verification')) {
abort(404);
}
}
/**
* Display the email verification notice.
*/
public function notice(Request $request): Response|RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(config('auth-ui.redirects.login', '/'));
}
return Inertia::render('Auth/VerifyEmail');
}
/**
* Handle the email verification.
*/
public function verify(EmailVerificationRequest $request): RedirectResponse
{
$request->fulfill();
return redirect()->intended(config('auth-ui.redirects.login', '/'));
}
/**
* Resend the email verification notification.
*/
public function resend(Request $request): RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(config('auth-ui.redirects.login', '/'));
}
$request->user()->sendEmailVerificationNotification();
return back()->with('status', 'verification-link-sent');
}
}