Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Turbo] Add mercure() to turbo_stream_listen() #1860

Open
seb-jean opened this issue May 21, 2024 · 5 comments · May be fixed by #2447
Open

[Turbo] Add mercure() to turbo_stream_listen() #1860

seb-jean opened this issue May 21, 2024 · 5 comments · May be fixed by #2447
Labels

Comments

@seb-jean
Copy link
Contributor

seb-jean commented May 21, 2024

Hi,

For generate the URL of the Hub and for automatically set the cookie required to use the authorization mechanism, we need Twig helper mercure() (PR: symfony/mercure#62)

But how to use it with turbo_stream_listen()?

@Guervyl
Copy link

Guervyl commented May 30, 2024

Yes, I have the same problem. In dev mercure is working fine but in production I can't use it. I'm getting 401.

@gremo
Copy link
Contributor

gremo commented Sep 1, 2024

Same problem/question here.

@smnandre
Copy link
Member

smnandre commented Sep 1, 2024

Could you guys set up a small reproducer app, with everything needed to test (like an example you need to work that does not today) ?

@gremo
Copy link
Contributor

gremo commented Sep 1, 2024

@smnandre I'll try probably tomorrow.

I'll try to explain better what I think @seb-jean is asking.

In short, mercure() helper does one important thing: it setup the cookie needed to subscribe to a topic (when authorization is needed, i.e. Mercure doesn't allow anonymous subscribers):

<script>
  const eventSource = new EventSource("{{ mercure('https://example.com/books/1', { subscribe: 'https://example.com/books/1' })|escape('js') }}", {
      withCredentials: true
  });
</script>

As you can see withCredentials is passed to the EventSource object. CORS and the cookie make the subscribe process work.

On the other hand, turbo_stream_listen does not set any cookie and does not support passing withCredentials to the Stimulus controller (let alone that the controller itself doesn't support options for the EventSource object).

So, what I think he is asking (and what I think it's needed is):

  • turbo_stream_listen should set the authorization cookie (is this possible?!)
  • turbo_stream_listen should support passing with withCredentials
  • The Stimulus controller should be modified too

See #1774

@seb-jean
Copy link
Contributor Author

seb-jean commented Sep 2, 2024

Yes, that's exactly it, plus the ability to subscribe to multiple topics.

@Fan2Shrek Fan2Shrek linked a pull request Dec 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants