Repository navigation
feat(server): signed-in visitors with identity tokens and budget tiers - #323
Merged
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
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.
Slice T9 of P1 (F-04 task 11): host-site identity,
uidon conversations, and tiers.Server (
identity: { secret, tiers? }, needssessionSecrets):/sessiontakes auserToken: an HS256 JWT signed by the host site withidentity.secret, withsub(the user id, up to 128 characters),exp, and an optionaltier. A token that doesn't verify, has expired or has nosubgets 401session_required, not an anonymous session, so a bug on the host site shows up. AuserTokenwithidentityoff gets 400.metadata.uidon the conversation with its first message, only when it has none.userToken, even without the old session token (a new device or cleared storage). Another user, or an anonymous visitor, gets a new conversation. A previous session token that belonged to another user doesn't carry over.identity.tiersmaps a tier to budgets merged overbudgets. Counts are shared, and the guards are built at startup, so a bad tier budget fails there.Widget:
userToken/data-user-token, sent with every/sessionrequest.ChatClientnow takes the widget config directly, which keeps the size at 14.29 kB of 14.5 kB.Docs: a "Signed-in visitors" section on the setup page, with a dependency-free Node signing sample. I checked that a token signed exactly as the sample does verifies with the server. The widget configuration page lists the option.
Checks: build, typecheck,
pnpm test:coverage(1159 passed). New tests: 6 server tests for stamping, resume across users, bad tokens, identity off, tiers and startup checks, plus a widget test for sending the token. Lint is at the dev baseline, size passes, and the website builds.