F
Filamentβ€’7mo 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!
10 Replies
RuZZZZ
RuZZZZOPβ€’7mo ago
After some thinking, I replaced return $this->hasVerifiedEmail(); in user model to return true; And now it does great
Tetracyclic
Tetracyclicβ€’7mo 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β€’7mo 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β€’7mo 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
RuZZZZOPβ€’7mo 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
RuZZZZOPβ€’7mo ago
I guess this will only partially help, because there is not just email verification route, but this one too
No description
Tetracyclic
Tetracyclicβ€’7mo 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
RuZZZZOPβ€’7mo ago
ty
Lupin
Lupinβ€’5mo ago
Hi,I want to ask how to get the email message from laravel .Did the exact step like you but did not get the email message
toeknee
toekneeβ€’5mo ago
php artisan queue:work ?
Want results from more Discord servers?
Add your server