#user registration->email verification?

16 messages · Page 1 of 1 (latest)

boreal sinew
#

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!

boreal sinew
#

After some thinking, I replaced return $this->hasVerifiedEmail(); in user model to
return true;
And now it does great

prime cargo
#

@boreal sinew 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.

lost pivot
#

As Tetracyclic says.... so if you want to disable it, remove the middleware instead to avoid the extra classes that you are not using.

prime cargo
#

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.

#

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();
}

(not tested this)

boreal sinew
#

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.

boreal sinew
prime cargo
#

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

lucid glacier