F
Filamentβ€’2mo ago
RuZZZZ

user registration->email verification?

Hey guys! Very simple expectations: User registers, gets an email, verifies email, access to panel granted. Until email is verified, can see a simple page that requires email verification and logout button. I added: ->login() ->registration() ->passwordReset() ->emailVerification() Also, in user: class User extends Authenticatable implements FilamentUser, MustVerifyEmail public function canAccessPanel(Panel $panel): bool { return $this->hasVerifiedEmail(); } Once I register, I a get 403, also, I get an email from laravel, but can't verify, when link clicked, I also get 403 πŸ™‚ https://my.domain.com/app/email-verification/verify/6/9cfe7a9376fb486b8ca0f44e7a1Ks9d90edbab?expires=1717465822&signature=cf90b6332309279d89ab36586c81e1161d9c0b5700598cfca6e0765f2e065430 Is there any good paper/document/tutotial on how to implement this? I checked website/s, this discord, reddit, chatgpt, claude πŸ™‚ Thanks!
8 Replies
RuZZZZ
RuZZZZβ€’2mo ago
After some thinking, I replaced return $this->hasVerifiedEmail(); in user model to return true; And now it does great
Tetracyclic
Tetracyclicβ€’2mo ago
@RuZZZZ returning true from hasVerifiedEmail() means that you've essentially disabled email verification. That method should check whether the user has verified their email. If it always returns true, the user never needs to verify their email.
toeknee
toekneeβ€’2mo ago
As Tetracyclic says.... so if you want to disable it, remove the middleware instead to avoid the extra classes that you are not using.
Tetracyclic
Tetracyclicβ€’2mo ago
I believe the email verification route is protected by Filament's authentication middleware, which in turn uses canAccessPanel(), so by requiring a verified email in canAccessPanel, it's getting stuck in a loop where it won't let you access the email verification route, because the email isn't verified yet. https://github.com/filamentphp/filament/blob/cecc1450bb52374a39f720c87262f65b9fc9a2a0/packages/panels/routes/web.php#L71 Instead of overwriting hasVerifiedEmail(), you could instead check in canAcessPanel whether the user is trying to access the email verification route, and if so return true, otherwise check hasVerifiedEmail() Something like:
public function canAccessPanel(Panel $panel): bool
{
if (Route::currentRouteName() === 'auth.email-verification.verify') {
return true;
}

return $this->hasVerifiedEmail();
}
public function canAccessPanel(Panel $panel): bool
{
if (Route::currentRouteName() === 'auth.email-verification.verify') {
return true;
}

return $this->hasVerifiedEmail();
}
(not tested this)
RuZZZZ
RuZZZZβ€’2mo ago
wow, someone actually read my dummy question πŸ™‚ Thanks >I believe the email verification route is protected by Filament's authentication middleware, which in turn uses canAccessPanel(), so by requiring a verified email in canAccessPanel, it's getting stuck in a loop where it won't let you access the email verification route, because the email isn't verified yet. I think this is precisely what happened.
RuZZZZ
RuZZZZβ€’2mo ago
I guess this will only partially help, because there is not just email verification route, but this one too
No description
Tetracyclic
Tetracyclicβ€’2mo ago
You could do str_starts_with(Route::currentRouteName(), 'auth.email-verification.') The two routes are auth.email-verification.verify and auth.email-verification.prompt, so you could also check them individually
RuZZZZ
RuZZZZβ€’2mo ago
ty
Want results from more Discord servers?
Add your server
More Posts