FE-M0-22 · An access change on the local stack, then merge pack B2
ID FE-M0-22 · Level L0 · Run order row 25b · Why D37, D48, R-ACC-48, R-ACC-04, R-GATE-04 · Issue #151
On the local stack, with the E2E logins: a change to a signed-in user's roles sends their next request to /login, which says their access changed; a user with no role at any pool gets /no-access after signing in, not an empty shell; when session_is_current() can't be called, the user is signed out too (fail closed); and the E2E roles that hold gate:write are super_admin, admin and satpam. Then pack B2 is merged.
There is no page to manage users until M1, so the access changes are made with SQL on the local database, as an admin's change would make them. The database's half of each change (ending sessions, stamping the profile) is pack G1's and was proven in BE-M0-35; this step proves apps/web's half.
Before
Section titled “Before”- FE-M0-21 is Done, on web/session-check.
- The local stack is running (
pnpm supabase start), and apps/web/.env.local points at it (FE-M0-06). - Nothing else runs on port 3000. Use one terminal for the app and a second one, in ~/opleet-v2/opleet, for everything else.
1 · The local database from main's migrations, and the E2E logins
Section titled “1 · The local database from main's migrations, and the E2E logins”pnpm supabase db resetpnpm db:e2e-users2 · Start the app and leave it running
Section titled “2 · Start the app and leave it running”pnpm --filter web dev3 · In the second terminal: the two logins this step uses. The password is E2E_PASSWORD in .env.e2e; never paste it anywhere
Section titled “3 · In the second terminal: the two logins this step uses. The password is E2E_PASSWORD in .env.e2e; never paste it anywhere”VIEWER=$(grep '^E2E_VIEWER_EMAIL=' .env.e2e | cut -d= -f2)SATPAM=$(grep '^E2E_SATPAM_EMAIL=' .env.e2e | cut -d= -f2)echo "$VIEWER $SATPAM"Keep this terminal open: blocks 5, 7, 9, 11 and 13 use the two names.
4 · In the browser, sign in at http://localhost:3000 as the viewer. Open the pool switcher in the top bar, then close it. Leave the tab open.
Section titled “4 · In the browser, sign in at http://localhost:3000 as the viewer. Open the pool switcher in the top bar, then close it. Leave the tab open.”5 · An access change: take away the viewer's role at pool E2B
Section titled “5 · An access change: take away the viewer's role at pool E2B”pnpm supabase db query --local "delete from public.member_roles mr using public.memberships m, auth.users u, public.pools p where m.id = mr.membership_id and u.id = m.profile_id and p.id = mr.pool_id and u.email = '$VIEWER' and p.code = 'E2B' returning p.code"6 · In the browser, reload the page. Then sign in again as the viewer.
Section titled “6 · In the browser, reload the page. Then sign in again as the viewer.”7 · Take away the viewer's last role
Section titled “7 · Take away the viewer's last role”pnpm supabase db query --local "delete from public.member_roles mr using public.memberships m, auth.users u where m.id = mr.membership_id and u.id = m.profile_id and u.email = '$VIEWER' returning mr.pool_id"8 · In the browser, reload, then sign in again as the viewer. Press Keluar on the page you get.
Section titled “8 · In the browser, reload, then sign in again as the viewer. Press Keluar on the page you get.”9 · Give the viewer back their roles, and list the E2E roles that hold gate:write
Section titled “9 · Give the viewer back their roles, and list the E2E roles that hold gate:write”pnpm db:e2e-userspnpm supabase db query --local "select r.code from public.roles r join public.role_permissions rp on rp.role_id = r.id where r.organization_id = 'e2e00000-0000-4000-8000-000000000001' and rp.permission_code = 'gate:write' order by 1"10 · In the browser, sign in as the satpam login and count the menu items. Leave the tab open.
Section titled “10 · In the browser, sign in as the satpam login and count the menu items. Leave the tab open.”11 · Make the check fail: for a moment, signed-in users may not call session_is_current()
Section titled “11 · Make the check fail: for a moment, signed-in users may not call session_is_current()”pnpm supabase db query --local "revoke execute on function public.session_is_current() from authenticated"12 · In the browser, reload. Then try to sign in again as the satpam login. Look at the first terminal's last lines.
Section titled “12 · In the browser, reload. Then try to sign in again as the satpam login. Look at the first terminal's last lines.”13 · Allow the call again, exactly as the migration grants it, and sign in as the satpam login once more
Section titled “13 · Allow the call again, exactly as the migration grants it, and sign in as the satpam login once more”pnpm supabase db query --local "grant execute on function public.session_is_current() to authenticated"Then stop the app with Ctrl+C in the first terminal.
14 · Push, open the pull request, merge
Section titled “14 · Push, open the pull request, merge”git push -u origin web/session-checkgh pr create --title "feat(web): sign out when access changes, and a pool required (d37)" --body "FE pack B2 (FE-M0-20 to FE-M0-22), timeline row 25b. Refs #151. Decisions: D37, D48. Rules: R-ACC-48, R-ACC-04, R-GATE-04."gh pr checks --watchgh pr merge --squash --delete-branchgit switch maingit pullExpect
Section titled “Expect”- Block 1: “Finished supabase db reset”, then “11 logins in the E2E organization, all pools. .env.e2e updated (password not shown).”
- Block 3: two addresses, e2e.viewer@… and e2e.satpam@….
- Block 4: the viewer lands on /dashboard. The pool switcher lists E2A and E2B.
- Block 5: one row, E2B.
- Block 6: the reload lands on /login, with a warning card “Anda sudah dikeluarkan” and “Anda dikeluarkan karena akses akun Anda berubah. Silakan masuk lagi.” above the form. After signing in, /dashboard opens again, and the top bar shows E2A only, with no list to open.
- Block 7: one row, a pool id.
- Block 8: the reload lands on /login with the same card. Signing in lands on /no-access: “Akun Anda belum punya akses” and “Akun ini belum punya peran di pool mana pun. Minta admin memberi Anda peran, lalu masuk lagi.”, with Keluar and no menu. Keluar opens /login, this time with no card.
- Block 9: the logins line as in block 1, then three rows: admin, satpam, super_admin.
- Block 10: satpam lands on /gate with 2 menu items, Gate and Log aktivitas.
- Block 11: no error.
- Block 12: the reload lands on /login with “Sesi Anda tidak bisa diperiksa, jadi Anda dikeluarkan demi keamanan. Silakan masuk lagi.” Signing in comes back to the same page and card: no page opens while the check fails. The first terminal shows
auth.session_check 42501. - Block 13: no error; satpam lands on /gate again.
- Block 14: checks and pr-title pass, then “✓ Squashed and merged pull request #…”.
git log --oneline -1Expect: “feat(web): sign out when access changes, and a pool required (d37) (#…)”.
If it fails
Section titled “If it fails”- Block 6 or 8: the reload opens the page instead of /login. Paste the first terminal's last lines. If they show no
session_is_currentcall at all, the proxy in use is not this branch's: checkgit branch --show-currentin the first terminal's folder. - Block 6: after signing in again, /login comes back with the card. The new sign-in happened within the same second as block 5's change, and a token issued in that second counts as older (R-ACC-48). Wait a moment and sign in again; if it still happens, paste the first terminal's last lines.
- Block 8 shows the shell with an empty menu instead of /no-access: paste the page's address and the first terminal's last lines.
- Block 9 lists other roles, or none: the roles page and the database disagree. Paste the rows; pack G1 gives gate:write to these three only (R-GATE-04).
- Block 12 opens the page instead of /login: stop, and paste the first terminal's last lines. That would mean an error lets a request through, which D37 forbids. Run block 13 before anything else.
- Anything went wrong between blocks 5 and 13: run
pnpm db:e2e-usersand block 13's query, orpnpm supabase db resetandpnpm db:e2e-users, to get the local database back.
gh pr close --delete-branchgit switch maingit branch -D web/session-checkBefore merging. After merging: revert it with a new pull request. The local database comes back with pnpm supabase db reset and pnpm db:e2e-users. Nothing in this step touches staging or production.
Not run yet. Log each run as a comment on #151. #151 closes when a clean run of FE-M0-20 to FE-M0-22 is logged.