docs: client authentication, connect uid and Japa testing#44
Merged
Conversation
Member
|
Thanks 👍🏽 |
Member
|
Could you also provide a PR for the documentation here https://github.com/adonisjs/v7-docs ? |
Contributor
Author
|
yes i will do it on monday :) |
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
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.
What
Extends the README with the three areas that were missing:
__transmit/subscribe/__transmit/unsubscribeare public by default, soctx.auth.userisundefinedunless those routes go through your auth middleware. Adds atransmit.registerRoutessnippet to protect them.@adonisjs/transmit-client, creating the client, and using thebeforeSubscribehook to attach anAuthorization: Bearer <token>header on every subscription request, plus subscribing and listening for messages.connect/disconnectevents expose the clientuid, which can be mapped to the authenticated user.transmit.on('broadcast', ...)(which returns a stop function), and how to test that an unauthenticated subscription is rejected with a401.Client,Testing).Why
The docs only covered server-side
transmit.authorize, with no guidance on authenticating the client, on the lifecycleuid, or on testing broadcasts. These are common needs when securing private channels.Notes
beforeSubscribereceives a singleRequestargument, so headers are mutated viarequest.headers.set(...).POST, so the auth test posts to/__transmit/subscribe.