DutchCodingCompany / filament-socialite

Add OAuth login through Laravel Socialite to Filament.
MIT License
153 stars 38 forks source link

Verification e-mail is not sent when registering new user #99

Closed renatofrota closed 4 months ago

renatofrota commented 4 months ago

Hello,

When e-mail verification is required, it's expected the verification link is sent automatically. Currently, the user is just redirected to the verification pending screen (where it's stated the e-mail has already been sent - while it's not).

dododedodonl commented 4 months ago

Thank you for using our package.

When using oauth, one most often trusts a third party to verify a user is who they say they are. In most cases, it would not be logical to have users verify their mail (again) in the application.

For this reason, a custom Registered event is triggered. In this event one can choose to set the email to verified (so regular registered users do have to verify their mail), dispatch laravel’s default registered event and/or trigger a verification mail.

renatofrota commented 4 months ago

Thank you.

I am using providers that do email validation so I went the first option: mark email as verified on signups (Registered event) and Socialite connections (SocialiteUserConnected event) to also cover the cases where the user is registered first (the normal way) then login using socialite.

php artisan make:listener MarkSocialiteUserAsVerified --event=Registered

customized app/Listeners/MarkSocialiteUserAsVerified.php like this:

<?php

namespace App\Listeners;

use DutchCodingCompany\FilamentSocialite\Events\Registered;
use DutchCodingCompany\FilamentSocialite\Events\SocialiteUserConnected;
use DutchCodingCompany\FilamentSocialite\Models\Contracts\FilamentSocialiteUser as FilamentSocialiteUserContract;

class MarkSocialiteUserAsVerified
{
    /**
     * Create the event listener.
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     */
    public function handle(Registered | SocialiteUserConnected $event): void
    {
        if ($event->socialiteUser instanceof FilamentSocialiteUserContract) {
            $event->socialiteUser->getUser()->markEmailAsVerified();
        }
    }
}

My suggestion: it could be a plugin option (global or per provider) to mark email as verified automatically on sign ups and Socialite connections (1st login using Socialite).