-
Notifications
You must be signed in to change notification settings - Fork 11
SendEmailVerificationNotification listener gets registered more times #35
Description
The EventServiceProvider of the AppShell library extends the Illuminate\Foundation\Support\Providers\EventServiceProvider class.
Beginning with Laravel 11, this automatically registers the Illuminate\Auth\Listeners\SendEmailVerificationNotification class as an event listener for the Illuminate\Auth\Events\Registered event. See Illuminate\Foundation\Support\Providers\EventServiceProvider::configureEmailVerification() function.
If AppShell is loaded as a Concord module, Illuminate\Foundation\Support\Providers\EventServiceProvider::register() will be called (at least) twice, resulting that the SendEmailVerificationNotification class will be registered (at least) twice as the listener for the Registered event.
What we did in our project to solve this issue:
- Defined our own
EventServiceProviderextendingIlluminate\Foundation\Support\Providers\EventServiceProviderand overwriting theconfigureEmailVerification()function to do nothing. - Extended our own
EventServiceProviderin every Concord module instead of theIlluminate\Foundation\Support\Providers\EventServiceProvider
Because we could not change theEventServiceProviderof the AppShell module, it still extendedIlluminate\Foundation\Support\Providers\EventServiceProvider, thus we had 2 registrations of theSendEmailVerificationNotificationlistener, so we - Defined a
Nooplistener:
namespace App\Listeners;
class Noop
{
public function handle()
{
// No operation
}
}- And bound it to the
Illuminate\Auth\Listeners\SendEmailVerificationNotification::classinApp\Providers\AppServiceProvider::register()
$this->app->bind(
\Illuminate\Auth\Listeners\SendEmailVerificationNotification::class,
\App\Listeners\Noop::class
);- Defined our own
App\Listeners\SendEmailVerificationNotificationlistener. This will automatically get registered by Laravel 11.
namespace App\Listeners;
use Illuminate\Auth\Events\Registered;
use Illuminate\Contracts\Auth\MustVerifyEmail;
class SendEmailVerificationNotification
{
/**
* Handle the event.
*
* @param Registered $event
* @return void
*/
public function handle(Registered $event)
{
if ($event->user instanceof MustVerifyEmail && ! $event->user->hasVerifiedEmail()) {
$event->user->sendEmailVerificationNotification();
}
}
}It would be nice to have a workaround in the AppShell module so that other users don`t have to follow these steps 😉.