vincent15000's avatar

Fortify verified doesn't verify email

Hello,

I'm using Fortify to authenticate a user.

I have this route.

Route::middleware(['auth', 'verified'])->group(function () {
    Route::get('dashboard', DashboardController::class)->name('dashboard');
});

But the user is immediately redirected to the dashboard without any email verification.

Do you have any idea why ?

Thanks for your help.

V

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

To ensure that email verification is working correctly with Laravel Fortify, you need to make sure a few things are set up properly. Here's a checklist and solution to address the issue:

  1. Ensure Email Verification is Enabled: Make sure that email verification is enabled in your User model. Your User model should implement the MustVerifyEmail interface.

    use Illuminate\Contracts\Auth\MustVerifyEmail;
    
    class User extends Authenticatable implements MustVerifyEmail
    {
        // ...
    }
    
  2. Check Middleware Configuration: Ensure that the verified middleware is correctly applied to your routes. It seems like you have done this correctly, but double-check your web.php or routes file.

  3. Verify Email Verification Views: Ensure that you have the necessary views for email verification. Laravel provides default views, but if you have customized them, make sure they are correctly set up.

  4. Check the Email Verification Process: Make sure that the email verification process is being triggered. When a user registers, they should receive an email with a verification link. If this is not happening, check your mail configuration in .env and ensure that your mail server is set up correctly.

  5. Test the Verification: After a user registers, they should receive an email with a verification link. Ensure that clicking this link correctly verifies the user's email.

  6. Debugging: If the above steps are correct and the issue persists, you can add some debugging to check if the verified middleware is being bypassed. You can do this by adding a simple log in the middleware to see if it's being hit.

    // In your middleware
    public function handle($request, Closure $next)
    {
        if (! $request->user() || ! $request->user()->hasVerifiedEmail()) {
            \Log::info('User is not verified.');
            return redirect()->route('verification.notice');
        }
    
        return $next($request);
    }
    
  7. Check for Customizations: If you have customized the Fortify service provider or any related logic, ensure that these customizations are not interfering with the email verification process.

By following these steps, you should be able to identify why the email verification is not working as expected. If the problem persists, consider checking the Laravel documentation or forums for any additional troubleshooting tips specific to your setup.

Please or to participate in this conversation.