FE-M0-20 · proxy.ts signs a user out when their access has changed
ID FE-M0-20 · Level L0 · Run order row 25b · Why D37, D48, D13, D29 · Issue #151
On every request from a signed-in user, proxy.ts calls session_is_current() after getClaims() (R-ACC-48). Unless the answer is a plain true, it ends this browser's session, clears the session cookies and sends the user to /login. An error, or no answer within five seconds, counts as not current: the check fails closed. /login then says why, through t() with an Indonesian default: “Anda dikeluarkan karena akses akun Anda berubah. Silakan masuk lagi.”, or, when the check failed, that the session couldn't be checked. Committed on the branch web/session-check.
Before
Section titled “Before”- BE pack G1 is merged (#154):
session_is_current()is in the migrations and in the generated types on main (BE-M0-35). - Pack D is merged, with FE-M0-16 (the fonts). This step's three changed files start from main as of 0ec8c64, and block 3 checks that first.
- Pack F (#173) is not merged yet. Its FE-M0-17 changes
i18n/messages.en.tstoo, so whichever of the two packs runs second needs its zip rebuilt by FE. Tell FE before running this pack if pack F has merged. - fe-pack-b2.zip, sent in the FE chat, is in ~/Downloads.
- You are in ~/opleet-v2/opleet and git status --short prints nothing.
- The Mac is online: the build fetches the fonts from Google (FE-M0-16).
1 · Check the zip, then unzip it next to the repository
Section titled “1 · Check the zip, then unzip it next to the repository”shasum -a 256 ~/Downloads/fe-pack-b2.zipunzip -q -o ~/Downloads/fe-pack-b2.zip -d ~/opleet-v2/packsls ~/opleet-v2/packs/fe-pack-b22 · A branch for pack B2
Section titled “2 · A branch for pack B2”git switch main && git pullgit switch -c web/session-check3 · Check the files this step replaces, then copy its files
Section titled “3 · Check the files this step replaces, then copy its files”The lines end in &&, so the block stops at the first command that fails.
shasum -a 256 -c ~/opleet-v2/packs/fe-pack-b2/FE-M0-20/BASE.sha256 && cp -R ~/opleet-v2/packs/fe-pack-b2/FE-M0-20/apps . && git status --short4 · Write the catalog again, then test, typecheck, lint and build
Section titled “4 · Write the catalog again, then test, typecheck, lint and build”pnpm --filter web i18npnpm --filter web testpnpm --filter web typecheckpnpm lintpnpm --filter web build5 · Commit
Section titled “5 · Commit”git add -A apps/webgit commit -m "feat(web): sign out when access changes (d37)"Expect
Section titled “Expect”- Block 1: 6c9ead71f15a3cd590cc285e7bf560b74bfcce441b09ad79c408e1ca61bf9d89, then FE-M0-20 FE-M0-21 README.txt.
- Block 2: “Switched to a new branch 'web/session-check'”.
- Block 3: three lines ending in “: OK”, for lib/supabase/proxy.ts, app/login/page.tsx and i18n/messages.en.ts; then M for apps/web/app/login/page.tsx, i18n/messages.en.ts and lib/supabase/proxy.ts, and ?? for lib/auth/session-check.test.ts and lib/auth/session-check.ts.
- Block 4: “Keys: 95. With English: 95. Without: 0.”; “ℹ tests 38” and “ℹ pass 38”, among them “✔ R-ACC-48: only a plain true from session_is_current() lets the request through” and “✔ R-ACC-48: an error from the check signs the user out (fails closed)”; typecheck with the same Keys line and no errors; “No fixes applied.”; the build lists ƒ /, ƒ /[...slug], ƒ /design-preview, ƒ /login and ƒ /no-access, then “ƒ Proxy (Middleware)”.
- Block 5: the commit line with 6 files changed (messages.id.ts among them, written by block 4).
grep -c 'rpc("session_is_current")' apps/web/lib/supabase/proxy.tsgrep -c 'auth.signed_out' apps/web/i18n/messages.id.tsExpect: 1, then 3: the call is in proxy.ts, and the three new texts are in the Indonesian catalog. The step on the local stack is FE-M0-22.
If it fails
Section titled “If it fails”- Block 3 prints “FAILED” for a file and stops: your copy of that file is not the one this step was written for. Most likely pack F has merged and changed messages.en.ts. Nothing was copied. Paste the FAILED lines and stop; FE rebuilds the zip.
- typecheck says
session_is_currentdoesn't exist on the database type: the generated types are older than pack G1. Rungit log --oneline -1 -- packages/db-typesand paste it; don't edit the types by hand (D22). - typecheck lists a key with no English: the zip's messages.en.ts was not copied. Run block 3 again.
- The build fails on “Failed to fetch Inter Tight from Google Fonts”: the Mac was offline. Connect and run block 4 again.
git switch maingit branch -D web/session-checkBefore anything is pushed. The step changed files on the branch only.
Not run yet. Log each run as a comment on #151.