Skip to content

SendEmailVerificationNotification listener gets registered more times #35

@hupupu

Description

@hupupu

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:

  1. Defined our own EventServiceProvider extending Illuminate\Foundation\Support\Providers\EventServiceProvider and overwriting the configureEmailVerification() function to do nothing.
  2. Extended our own EventServiceProvider in every Concord module instead of the Illuminate\Foundation\Support\Providers\EventServiceProvider
    Because we could not change the EventServiceProvider of the AppShell module, it still extended Illuminate\Foundation\Support\Providers\EventServiceProvider, thus we had 2 registrations of the SendEmailVerificationNotification listener, so we
  3. Defined a Noop listener:
namespace App\Listeners;

class Noop
{
    public function handle()
    {
        // No operation
    }
}
  1. And bound it to the Illuminate\Auth\Listeners\SendEmailVerificationNotification::class in App\Providers\AppServiceProvider::register()
        $this->app->bind(
            \Illuminate\Auth\Listeners\SendEmailVerificationNotification::class,
            \App\Listeners\Noop::class
        );
  1. Defined our own App\Listeners\SendEmailVerificationNotification listener. 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 😉.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions