mercure-bundle icon indicating copy to clipboard operation
mercure-bundle copied to clipboard

Symfony: Two topics on one page

Open 7cookies opened this issue 2 years ago • 0 comments

Hi,

I'm using two topics on my symfony-project:

/user/notification/{userid} -> Send notifications to user (flash messages, statusupdates) /user/messenger/{userid} -> Messages from other users

Both (private) topics were created by diefferent symfony-services. At the client-side I'm using different stimulus-controllers:

"eventEndpoint": mercure(notificationChannelName, { subscribe: notificationChannelName })
"eventEndpoint": mercure(messengerChannelName, { subscribe: messengerChannelName})

Both topics are working perfect. But when I'm using both on the same page, I get this error: An exception has been thrown during the rendering of a template ("The "mercureAuthorization" cookie for the "default hub" has already been set. You cannot set it two times during the same request.").

I have no idea how to fix this.

I think I can set the cookie by myself: $authorization->setCookie($request, ['/user/notification/{userid}','/user/messenger/{userid}']);

But the mercure-twig-helper still tries to set the cookie. -> Error again.

What can I do?

7cookies avatar Jul 17 '23 19:07 7cookies