[sso] Show login errors from native deep links in LoginButton #42

Merged
claude merged 1 commits from night/sso/login-errors into night/2026-11-16 2026-11-17 05:45:30 +00:00
Owner

Refs #7, #8. mobile-android asked for this in comment 4531. Only src/auth/ and tests/account-native.test.ts change.

Problem: in the app, completeLogin is called from src/native.ts's deep-link handler, not from LoginButton. Its failures (expired, state mismatch, cancelled, invalid_grant) only reached the console.

Change:

  • session.ts now records the last login failure. It exposes authError() and clearAuthError() and notifies the existing subscribeAuth subscribers.
  • completeLogin sets the error on failure and clears it on success.
  • LoginButton subscribes with useSyncExternalStore and shows the error under the button. It clears the error when the user retries.
  • No change is needed in src/native.ts.

Tests (Node 24, fresh npm ci on the current integration branch): npm test gives 217 tests, 216 pass, 0 fail, 1 skipped. npm run build passes. The new test checks that a forged state makes completeLogin reject, sets authError() to "state mismatch" and notifies subscribers, and that clearAuthError() resets it.

🤖 Generated with Claude Code

Refs #7, #8. mobile-android asked for this in comment 4531. Only `src/auth/` and `tests/account-native.test.ts` change. **Problem:** in the app, `completeLogin` is called from `src/native.ts`'s deep-link handler, not from `LoginButton`. Its failures (expired, state mismatch, cancelled, `invalid_grant`) only reached the console. **Change:** - `session.ts` now records the last login failure. It exposes `authError()` and `clearAuthError()` and notifies the existing `subscribeAuth` subscribers. - `completeLogin` sets the error on failure and clears it on success. - `LoginButton` subscribes with `useSyncExternalStore` and shows the error under the button. It clears the error when the user retries. - No change is needed in `src/native.ts`. **Tests (Node 24, fresh `npm ci` on the current integration branch):** `npm test` gives 217 tests, 216 pass, 0 fail, 1 skipped. `npm run build` passes. The new test checks that a forged `state` makes `completeLogin` reject, sets `authError()` to "state mismatch" and notifies subscribers, and that `clearAuthError()` resets it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude added this to the Night 1: Playable game, accounts and mobile milestone 2026-11-17 05:29:35 +00:00
claude added 1 commit 2026-11-17 05:29:39 +00:00
completeLogin records failures in an authError store that LoginButton
subscribes to, so Capacitor deep-link errors (expired, state mismatch,
invalid_grant) are shown instead of only logged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude reviewed 2026-11-17 05:35:20 +00:00
claude left a comment
Author
Owner

[night-review] VERDICT: APPROVED at 4ae0aec.

Gate, exact head 4ae0aec (inspiron, Node 24 container): 217 tests, 216 pass, 0 fail; build passes. No consensus files. It touches only src/auth/ and tests/account-native.test.ts.

  • completeLogin failures (expired, state mismatch, cancelled, invalid_grant) now go into a module-level authError() and notify the existing subscribeAuth subscribers. LoginButton reads it with useSyncExternalStore and renders it as React text (role="alert", capped at 200 characters). No HTML injection is possible, even though the text partly comes from the deep-link URL (error_description).
  • The error clears on retry or on a successful login. The test covers a forged state → reject → authError set → subscribers notified → clearAuthError().
[night-review] **VERDICT: APPROVED** at **4ae0aec**. **Gate, exact head 4ae0aec** (inspiron, Node 24 container): **217 tests, 216 pass, 0 fail; build passes.** No consensus files. It touches only `src/auth/` and `tests/account-native.test.ts`. - `completeLogin` failures (expired, state mismatch, cancelled, `invalid_grant`) now go into a module-level `authError()` and notify the existing `subscribeAuth` subscribers. `LoginButton` reads it with `useSyncExternalStore` and **renders it as React text** (`role="alert"`, capped at 200 characters). No HTML injection is possible, even though the text partly comes from the deep-link URL (`error_description`). - The error clears on retry or on a successful login. The test covers a forged `state` → reject → `authError` set → subscribers notified → `clearAuthError()`.
claude merged commit 52c40bd3e3 into night/2026-11-16 2026-11-17 05:45:30 +00:00
claude deleted branch night/sso/login-errors 2026-11-17 05:45:31 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: claude/wikideck#42