How to Fix Email Verification in FilamentPHP

If you’re dealing with a 403 error when signing up on your FilamentPHP application, don’t worry. Here’s a simple fix […]

If you’re dealing with a 403 error when signing up on your FilamentPHP application, don’t worry. Here’s a simple fix to get your email verification working properly.

Step 1: Update AdminPanelProviders

First, ensure you have ->emailVerification() added in your app/Providers/Filament/AdminPanelProviders.php within the panel method. It should look something like this:

public function panel(Panel $panel): void
{
	$panel
		->login()
		->registration()
		->passwordReset()
		->emailVerification() // < This right here
}

Step 2: Modify the User Model

This part is where the documentation is slightly misleading. Documentation says that you need to add $this->hasVerifiedEmail() in the canAccessPanel method. But if you’re implementing Illuminate\Contracts\Auth\MustVerifyEmail then you don’t need that. Instead, it should simply return true. Here’s how you should do it:

....

public function canAccessPanel(Panel $panel): bool
{

	return true;

}

Finally, just make sure that your User Model implements FilamentUser and MustVerifyEmail (as stated above as well). It should look like this:

use Filament\Models\Contracts\FilamentUser;
use Illuminate\Contracts\Auth\MustVerifyEmail;

class User extends Authenticatable implements FilamentUser, MustVerifyEmail
{
	// Your User Model code

	public function canAccessPanel(Panel $panel): bool
	{

		return true;

	}

}

Summary

That’s it! Just follow these steps:

  1. Add ->emailVerification() in AdminPanelProviders.php.
  2. Ensure canAccessPanel method returns true in the User Model.
  3. Make sure the User Model implements FilamentUser and MustVerifyEmail.

By making these changes, you should resolve the 403 error and get your email verification working seamlessly.

If you have any questions or run into issues, feel free to reach out. Happy coding!