fix(auth): show live subscription plan in whoami - #63
Open
syf2211 wants to merge 2 commits into
Open
Conversation
Fetch plan from authenticated /v1/me/usage (quota headers or JSON body) instead of relying on an unpopulated credentials field. Also capture plan from the OAuth callback when the web redirect includes it. Fixes KlaatAI#24
Extract mergeUsagePlan static helper and unit-test it directly so login.test.ts module mocks do not break getUsageStats coverage in CI.
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.
Summary
klaatai whoaminow resolves the user's subscription plan from the authenticated/v1/me/usageendpoint instead of an unusedcredentials.jsonfield.Motivation
Fixes #24 —
Credentials.planwas never written at login andwhoamionly called/health, so every signed-in user sawplan: null.Changes
getUsageStats()extractsplanfromX-KlaatAI-Quota-Plan(or legacy header) and optional JSONplanrunWhoami()fetches usage in parallel with the health check and prefers live plan over stored credentialsplanwhen the web redirect includes it (forward-compatible)Tests
bun run typecheck— passbun test— 449/449 passbun run build— passNotes
/v1/me/usage(header or JSON) for users who have not chatted yet; OAuthplanparam is an additional path when the web login redirect adds it./whoamistill uses chat quota headers — possible follow-up, out of scope here.Fixes #24