Skip to content

fix: use current Supabase login for Flask API requests - #206

Open
BrandDead wants to merge 2 commits into
main-tL2525from
fix/175-sdk-session-http
Open

BrandDead wants to merge 2 commits into
main-tL2525from
fix/175-sdk-session-http

Conversation

@BrandDead

@BrandDead BrandDead commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Outcome

Flask API requests now follow the Supabase session used by the existing login screen, including current token/account changes and SDK-managed refresh. Pending requests cannot replay or deliver an old-account response after the account changes.

Scope

In: frontend/src/services/api.service.ts, its new 16-case auth regression suite, a dated project-log entry, and text verification under docs/evidence/2026-10-14-current-auth-api/.

Reserved files: the two API/test files above; project log is append-only. No existing #204/#205/#202/#169 implementation file is changed.

Contracts preserved

  • One existing Supabase auth session; no new token store or navigation authority.
  • Concurrent 401 responses share SDK refresh; requests replay at most once. A late 401 can use an already rotated token.
  • Sign-out clears outgoing authorization. Account changes are checked before replay and response delivery.
  • SDK initialization is deferred so pure offline store imports remain usable.
  • Prove authenticated saved-game continuity on isolated staging #175 stays open: source contract/local demo proof is separate from live authenticated saved-game/RLS continuity.

Verification

  • Final regression suite on unchanged 9eef5aa: 12 failed / 4 passed; corrected source: 16 passed.
  • Independent auth plus existing offline-store suites with no VITE credentials: 27 passed.
  • Full local frontend: 1,049 passed / 4 existing skips, 92 files; TypeScript, lint, assets/packages and production build passed. Lint: 0 errors / same 200 warnings / 0 new warnings.
  • The exact service was also rebuilt with fix: connect ATTACK planning to confirmed block responses #204/fix: render Nightfall role art and align tactical taps #205 and passed phone 390×844, desktop 1440×900 and phone actor-image-failure paths through actual movement, fire/reload, retreat/apply and reload with one unchanged local receipt. The complete local combination passed 1,069 frontend tests and 131 backend tests; those other PRs remain separate.
  • Exact published tree matches the verified local publication tree 248ad40a80aa33a955fc213143a043d4a6a30057. Published exact-head CI passed on c3f0de5: 1,049 frontend tests passed / 4 existing skips; 107 unchanged-backend tests passed; type/lint/assets/packages/build passed. Vercel preview status is Ready.

Diagnostics and limits

Lazy SDK loading adds a recorded Rollup advisory because the app also imports that module statically; no second client or separate chunk is created. Existing legacy-image references and large-chunk warnings remain. Live #175, physical-device performance and human PvP are unproven by this PR.

Operational impact

No backend, schema, RLS, credentials, scheduler, production or deployment change. Revert this focused PR for source rollback.

Integration notes

Refs #175; closes nothing. Independent of #204, #205, #202 and #169. Preserve every dated project-log addition during integration. No merge or deployment is requested.

Review availability

Independent local review is complete. GitHub Codex code review is running; security review is completed. No inline review threads were present at this check. Cursor Bugbot could not run because its usage/spend limit was reached; no budget setting was changed. This is not a merge or release approval.


Note

Medium Risk
Client auth and token-refresh behavior changed for all Flask traffic, and block collection economy paths were altered; risk is mitigated by broad regression tests but session edge cases still warrant review.

Overview
Flask HTTP calls now attach the active Supabase SDK session (lazy-loaded) instead of legacy localStorage tokens, with SDK-managed refresh, shared concurrent 401 refresh, and guards that block delivering or replaying responses/mutations after sign-out or account switch via AccountChangedError.

Block income collection no longer treats those account-change failures as offline: it skips vault deposit and pending-income clear, shows an account-changed toast, and adds in-flight/double-tap protection while same-account offline collect still pays once.

Adds 16 API auth regressions and 4 BlockModeView collect/account-switch tests, plus dated project-log and evidence docs. Frontend-only; no backend or deploy changes.

Reviewed by Cursor Bugbot for commit 7e75c3c. Bugbot is set up for automated code reviews on this repo. Configure here.

Outcome

Flask API requests follow the Supabase session used by the existing login screen, including current token/account changes and SDK-managed refresh. Pending requests cannot replay or deliver an old-account response after the account changes.

A collection that finishes during an account switch no longer pays the local owner who is still mounted.

P1 repair (2026-10-16)

Codex review on c3f0de5 (discussion): if collect is in flight and the account changes, Flask can commit before the post-response identity check rejects the success. BlockModeView.handleCollect treated every rejection as offline and called collectIncome plus vaultDeposit, so the mounted save received a second payout.

Fix: account changes reject with AccountChangedError (including a 401 whose refresh would land on another user, and sign-out). The collect handler does not deposit or clear pending income for that error. A same-tick double tap sends and applies one collection. A same-account network failure still collects locally once.

Regression: on unchanged c3f0de5 the new suite failed because the mounted owner was paid $250 and a double tap sent two collects. After 7e75c3c it passes.

Scope

In: frontend/src/services/api.service.ts, frontend/src/components/map/BlockModeView.tsx, frontend/src/services/__tests__/api.service.auth.test.ts, frontend/src/components/map/BlockModeView.collectAccount.test.tsx, a dated project-log entry.

Out: #175 two-user staging proof, #209 inventory, DRIVE, ATTACK, backend, schema, RLS, secrets, Vercel env, production Supabase.

Reserved files: the API client, BlockModeView collect path, and the two test files above. Project log is append-only.

Contracts preserved

  • One existing Supabase auth session; no new token store or navigation authority.
  • Concurrent 401 responses share SDK refresh; requests replay at most once. A late 401 can use an already rotated token.
  • Sign-out clears outgoing authorization. Account changes are checked before replay and response delivery, and that rejection is not an offline payout.
  • SDK initialization is deferred so pure offline store imports remain usable.
  • Same-account offline collect still uses the local pending-income fallback exactly once.
  • Prove authenticated saved-game continuity on isolated staging #175 stays open: source contract/local demo proof is separate from live authenticated saved-game/RLS continuity.

Verification

  • Before the fix, BlockModeView.collectAccount.test.tsx failed: committed collect and post-switch 401 each deposited $250 into the mounted owner and cleared pending income; a double tap called collect twice.
  • After the fix: collect account-switch suite 4 passed; auth suite 16 passed; BlockModeView chrome 1 passed.
  • Full local frontend: 1,053 passed / 4 existing skips. tsc --noEmit clean. Touched-file eslint clean (removed the unused player.bankBalance dependency on the edited collect callback). The pre-existing repo lint errors were not part of this change.
  • Backend pytest was not run locally; this change does not touch the backend.
  • Pushed CI on 7e75c3c: run 38958921461 — Frontend (lint + build) success, Backend (pytest) success. Vercel preview status success. Cursor Bugbot neutral.
  • Player click evidence is the component test: Collect shows “Account changed. Collection was not applied to this save.” and leaves street cash, vault, pending income, and the ledger unchanged. Same-account success shows one “Collected $250!” and one vault ledger row.

Operational impact

No backend, schema, RLS, credentials, scheduler, production, or deployment change. Revert this focused PR for source rollback. Pushing the existing PR branch lets the already-connected preview workflow rebuild; nothing was promoted.

Integration notes

Refs #175; closes nothing. Independent of #204, #205, #202, #169, and #209. Preserve every dated project-log addition during integration. Block and shoebox stores are still not reset on account switch; this repair only stops the in-flight collect from paying the mounted owner. No merge or deployment is requested.

Open in Web Open in Cursor 

@vercel

vercel Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
slide Ready Ready Preview Oct 16, 2026 8:00pm UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T02:27:05.249892Z c3f0de5 PR opened
🔒 Security Review ✅ Completed 2026-10-15T02:24:50.051315Z c3f0de5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cursor

cursor Bot commented Oct 15, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: 013d63c5-2539-4aba-a3eb-fddc824bcffc)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c3f0de5255

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +105 to +108
async (response) => {
const session = await getCurrentSession();
requireSameAccount(response.config, session?.user.id ?? null);
return response;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prevent committed responses from triggering local fallbacks

If a player switches accounts while collect is in flight, Flask can commit the collection before this post-response identity check rejects the successful reply. BlockModeView.handleCollect treats every rejection as an offline failure and calls collectIncome plus vaultDeposit, so Alice's server-side collection can be followed by a local collection in Bob's still-mounted, persisted stores. Return a distinct non-fallback result for post-commit account changes, or cancel/reset consumers on the auth transition so a committed mutation cannot enter the offline path.

AGENTS.md reference: AGENTS.md:L12-L15

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Integration-owner handoff from the 2026-10-15 ten-PR audit: please retain ownership of this auth slice and address the existing unresolved P1 review (#206 (comment)) before integration, with a regression for the committed collect/account-switch failure path. I have not edited this branch or the overlapping ATTACK/BlockModeView files. Manus PR #209 is an independent inventory/TRAP/demo-reseed repair with no runtime-file overlap. #175 still needs the separately approved staging two-user/reload/second-session proof; nothing here was treated as beta or production authorization.

A committed or rejected collect was treated as an offline failure and paid the local owner still mounted. Account changes now stay out of that fallback, and a double tap applies one collection.

Co-authored-by: yourbranddead <yourbranddead@gmail.com>
@cursor

cursor Bot commented Oct 16, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: fef698b3-31e4-41e0-9456-cbd3ee1e444a)

This branch was successfully deployed

1 active deployment
Preview — 7e75c3c9 Deployed Oct 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants