SymfonyCasts/verify-email-bundle

Wrong URI using Messenger

laferte-tech opened this issue · 2 comments

Hi all,

first, thanks a lot for your amazing work.

I would like to use your bundle but i am experiencing a small issue with Messenger and the URI.
My setup on docker:
front: test.localhost (SPA)
back: api.test.localhost (with Symfony and Messenger).

To sum-up:
with sending the link inside messenger, uri is like: localhost/verify...
without messenger the link is good: api.test.localhost/verify...

When a user register on the front, i'm sending an API call to the backend. I have an entity listener on my User entity. On the postPersist, i'm dispatching an event to messenger:

$this->eventBus->dispatch(new userCreatedEvent($user->getId()));
then in my handler, i call a command to send the verification link:

        if (!$user->getIsVerified()) {
              $this->registrationVerification->sendEmailVerification($user);
        }

This method is then your code with:

        $signatureComponents = $this->verifyEmailHelper->generateSignature(
            $verifyEmailRouteName,
            $user->getId(),
            $user->getEmail()
        );

and so the problem is here (not related to this bundle i agree):
$uri = $this->router->generate($routeName, $extraParams, UrlGeneratorInterface::ABSOLUTE_URL);
when inside Messenger, it's taking localhost, when directly calling (registrationVerification->sendEmailVerification($user)) in the postPersist it's working great.

Do you have any idea about this?
Thanks a lot for your help

Howdy @GrandOurs35 and thanks for using VerifyEmailBundle! I actually just experienced this "problem" a few days ago myself..

Thankfully its a simple fix https://symfony.com/doc/current/reference/configuration/framework.html#default-uri
In my application I set the default_uri to pull a env variable to get the correct URI depending on the environment. Check out the example below.

// config/packages/routing.yaml

framework:
    router:
        utf8: true
        default_uri: '%env(resolve:APP_DOMAIN)%'
// .env

APP_DOMAIN=http://rushlow.dev

I hope this helps. Let me know if this solution does not work for you.

Hi!
Yes it works, thank you so much for your help :)