feat: claim a guest's data on the next real sign-in - #168
Conversation
Add MagicStarterGuestClaim and GuestClaimOutcome: record a guest's token on its sign-in, then claim POST /auth/guest/claim on the next real sign-in or restore, over a bare driver the devtools do not record. One claim per session is shared by concurrent callers and bound to the session that started it. A 2xx response marks the claim claimed, a 404 or 422 marks it refused and forgotten, anything else keeps the record for a later attempt. The record is forgotten on every sign-out before Auth.logout() returns. Add the onGuestClaimed hook (a bootstrap argument, useGuestClaimed), docs, a README row and a CHANGELOG entry.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Note Kodizm (AI-generated). May contain mistakes; verify before acting. The guest-claim flow looks sound and well tested. I found one gap: the error-handling promise in the docs doesn't match the code for callers who await Major
Tests
CI
|
_claimOnce only caught MagicVaultException, so an injected driver that throws would propagate past claimIfPending() to a host awaiting it, even though the doc promises it never throws on ordinary paths. Wrap the driver's post call in its own try/catch, log any exception with Log.error, and answer GuestClaimOutcome.none without touching the record so the next sign-in or restore retries. Updates the claimIfPending doc to state precisely that the configured driver turns transport failures into responses and that any exception the driver still raises is logged and answered as none.
|
The default Fixed in New test: @kodizm review |
|
Note Kodizm (AI-generated). May contain mistakes; verify before acting.
Changes since the last review:
TestsThe new test in CI
|
What is added
MagicStarterGuestClaimandGuestClaimOutcome: record a guest's token on its sign-in, then claimPOST /auth/guest/claimon the next real sign-in or restore, over a bare driver the devtools do not record. One claim per session is shared by concurrent callers and bound to the session that started it. A 2xx response marks the claim claimed; a 404 or 422 marks it refused and forgotten; anything else keeps the record for a later attempt. The record is forgotten on every sign-out beforeAuth.logout()returns.onGuestClaimedhook (a bootstrap argument,useGuestClaimed).Uses only magic API already on magic
master(sibling-compile).Sibling-compile note
No version bump and no publish. This targets
mainfor local override consumption bywatchoolswhile its adoption PR is open.Naming collision note
GuestClaimOutcomecollides by name with watchoolsmaster's own copy of the same type. A local override pointing watchools at a starter checkout carrying this PR breaks watchoolsmasteruntil the watchools adoption PR merges. Hosted builds are protected by the caret, so this only affects override-based local builds.Local gates
1626 tests, analyze and format clean.