Repository navigation
Conversation
…ckout socket tokens - In-memory authEngine delivers a customer socket token (POST storefront/v1/customers/socket-token, store key + Customer-Token) in the handshake; never persisted, never in the URL query. - Refresh at expires_in - 60s via socket.authenticate; recover from deauthenticate/kickOut/subscribeFail by re-minting, re-authenticating and resubscribing tracked channels (bounded retries). - Re-authenticate on login, reconnect anonymously on logout. - Guest QPay checkout authenticates with the checkout-scoped socket_token from checkout initialize before subscribing to checkout.<id>. - 404 from the mint route (older server) or no customer => anonymous, as before. - Handshake query carries client=storefront-app/<version>.
This was referenced Oct 6, 2026
feat(socket-auth): show channel authorization failures in the sockets viewer
fleetbase/dev-engine#51
Open
Open
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
Authenticates the app's realtime SocketCluster connection so it keeps working when the socket server enforces per-channel authorization.
src/utils/socket-auth.ts): logged-in customers mint a short-lived token fromPOST storefront/v1/customers/socket-token. The request uses the store key as Bearer and theCustomer-Tokenheader, which is how every other customer request is authenticated. It reuses the existing storefront adapter's host, namespace and headers. No SDK release is needed.authEngineonsocketClusterClient.create.loadTokenfetches a fresh token when there is none or when the current one expires within 60 s. The token is never written to MMKV, AsyncStorage or localStorage, and never goes in the URL query.expires_in - 60sviasocket.authenticate(newToken).deauthenticate, or onkickOut/subscribeFailfor a tracked channel, the client mints a new token, re-authenticates and resubscribes the channels opened through the context. Retries are bounded per channel and per auth failure. Existing channel consumers keep working because SC routes channel data by name.use-qpay-checkoutauthenticates the socket with the checkout-scopedsocket_tokenfrom the checkout initialize response before subscribing tocheckout.<id>. Logged-in customers' own tokens already cover their checkouts. The response may givesocket_tokenas either the mint object or a bare string, and both are accepted.client=storefront-app/<version>. The version comes from the app version on native and frompackage.jsonon web.SocketClusterContextboth use the shared manager.useSocketClusterClientnow also exposesauthenticateWithCheckoutToken.Why
Part of authenticated realtime channels: the socket server will only let a client subscribe to channels its token covers, such as the customer's own orders and the drivers/vehicles on them, or a guest's own checkout.
Old-server fallback
If the mint route returns 404 (the server has no socket auth or is an older release), there is no customer, or the request fails, the app connects anonymously, exactly as today. A 404 is remembered until the next login, so the route is not hit again on every reconnect. If
socket_tokenis absent from the checkout response, nothing changes.Notes
checkouts/statuspolling (on focus or app resume) still completes the order.FLEETBASE_KEYclient is unchanged and is not used for socket tokens.Test plan
order.<id>updates, and the token refreshes about 60 s before expiry without dropping the subscription.checkout.<id>completion event.The repo has no active unit-test setup (CI's test step is commented out), so no tests were added.
Related PRs
Part of the authenticated realtime channels rollout (socket auth), one PR per repo:
fleetbase/core-api ^1.6.69)fleetbase/fleetbase-socketserver, compose/helm/installer, console socket test page