-
-
Notifications
You must be signed in to change notification settings - Fork 42
feat: add Twig helper generating hub URLs and setting authorization cookies #62
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e14e5c8
to
670f7b0
Compare
670f7b0
to
f8696e6
Compare
lyrixx
reviewed
Jun 25, 2021
weaverryan
reviewed
Jun 25, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very compelling idea :)
79092e7
to
b5d97a3
Compare
chalasr
reviewed
Jun 27, 2021
939eb1b
to
5cd7372
Compare
0779c7d
to
ab2b33e
Compare
chalasr
approved these changes
Jun 28, 2021
This was referenced May 18, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR dramatically improves the Developer eXperience of the Mercure integration in Symfony. It can be considered as part of the Symfony UX initiative.
At a glance, it introduces a new Twig helper allowing to generate the URL of the Hub and to automatically set the cookie required to use the authorization mechanism:
In a single call, this helper:
topic
query parameters (currently, passing the URL of the Hub to Twig requires some collaboration from a controller, or to define a global environment variable, and encoding the topics may not be straightforward for users not familiar with modern JavaScript APIs)mercureAuthorization
cookie containing the valid JWT to subscribe to topics matching the passed URI templates (currently, setting this cookie require collaboration from the controller, and isn't straightforward)Subscribing to Mercure updates can be considered as part of the View layer. This new helper allows subscribing directly from Twig, without having to write any boilerplate code.
Then, a call to
HubInterface::publish()
from any service or controller is enough for the client to receive the push!This will also allow improving the developer experience of Symfony Turbo by having native support for authorization.
Here is the list of all available options:
I also revamped a bit #60 (cc @norkunas) to leverage the new infrastructure. In a following PR, I'll use this to allow to automatically clear the cookie when the user logs out from the site.
PR for MercureBundle: symfony/mercure-bundle#57
TODO: