Skip to content

BE-M0-30 · E2E logins on staging, each role signed in

ID BE-M0-30 · Level L0 · Pack Pack F · Staging · Run order row 32 · Issue #22

Staging has one login per system role in the E2E organization, made by pnpm db:e2e-users --staging (BE-M0-25). Each login signs in against staging and holds exactly its role's permissions at both E2E pools. A visitor who isn't signed in reads nothing. The logins share the password already in the git-ignored .env.e2e, so Playwright reads the same file for local and staging. This step changes no file in the repository.

  • BE-M0-29 is Done: staging holds the 13 migrations and the seed, and its check printed [{"slug":"e2e"}].
  • .env.e2e exists from BE-M0-25 with mode 600. The script reuses its E2E_PASSWORD; if the file is missing, the script makes a new password and writes it there.
  • The password manager is open on the "Opleet v2 staging" entry. The check asks for the publishable key, which starts with sb_publishable_. It's public by design (D13).

1 · From main, clean, and linked to staging

Section titled “1 · From main, clean, and linked to staging”
Terminal window
cd ~/opleet-v2/opleet
git switch main && git pull
git status --short
ref="$(cat supabase/.temp/project-ref)"; want="$(sed -n 's/^STAGING_PROJECT_REF=//p' .env.staging)"; [ -n "$ref" ] && [ "$ref" = "$want" ] && echo "linked to staging" || echo "STOP: not linked to staging"

The script reads SUPABASE_URL, SUPABASE_SECRET_KEY and STAGING_PROJECT_REF from .env.staging. It refuses any host but <STAGING_PROJECT_REF>.supabase.co, so it can't reach v1 or production. It never prints the password.

Terminal window
pnpm db:e2e-users --staging

3 · .env.e2e is still private and complete

Section titled “3 · .env.e2e is still private and complete”
Terminal window
git check-ignore -v .env.e2e
stat -f '%Lp' .env.e2e
grep -c '^E2E_' .env.e2e
  • Block 1: git status --short prints nothing, then "linked to staging".
  • Block 2: eleven lines starting with "made", one per role from super_admin to viewer with its address (e2e.super-admin@e2e.opleet.test and so on), then "11 logins in the E2E organization, all pools. .env.e2e updated (password not shown)." On a later run the lines say "kept" instead of "made".
  • Block 3: .gitignore:44:.env.e2e .env.e2e, then 600, then 12.

Each role signs in against staging and asks the database what it may do. The block prints one line per role: the role, then the number of pool and permission pairs it holds. Then it reads drivers without signing in. It runs in a subshell, so the keys, the password and the tokens are gone when it ends; none of them is printed.

Terminal window
(
set -a; . ./.env.staging; . ./.env.e2e; set +a
read -r "PK?Staging publishable key (sb_publishable_…): "
for role in super_admin admin admin_driver admin_fleet finance background_check maintenance asuransi checker satpam viewer; do
var="E2E_${role:u}_EMAIL"
token=$(curl -s "$SUPABASE_URL/auth/v1/token?grant_type=password" -H "apikey: $PK" -H "Content-Type: application/json" -d "{\"email\":\"${(P)var}\",\"password\":\"$E2E_PASSWORD\"}" | python3 -c 'import json, sys; print(json.load(sys.stdin).get("access_token", ""))')
n=$(curl -s -X POST "$SUPABASE_URL/rest/v1/rpc/my_permissions" -H "apikey: $PK" -H "Authorization: Bearer $token" | python3 -c 'import json, sys; d = json.load(sys.stdin); print(len(d) if isinstance(d, list) else "error")')
print -r -- "$role $n"
done
curl -s "$SUPABASE_URL/rest/v1/drivers?select=id" -H "apikey: $PK" | python3 -c 'import json, sys; d = json.load(sys.stdin); print("anon", d.get("code") if isinstance(d, dict) else len(d))'
)

Exactly these twelve lines. Each count is the role's permissions on the roles reference, at the two E2E pools, E2A and E2B:

super_admin 92
admin 84
admin_driver 30
admin_fleet 42
finance 14
background_check 8
maintenance 26
asuransi 32
checker 26
satpam 6
viewer 36
anon 42501

The last line says a visitor who isn't signed in is refused the table outright (R-ACC-02).

  • "refusing …": the script found a URL that isn't the staging project named in .env.staging. Paste that line, not the file. Don't change the script.
  • "--staging needs STAGING_PROJECT_REF in .env.staging" or "… SUPABASE_SECRET_KEY …": .env.staging is missing a line. Open it with open -e .env.staging and compare it with TL-M0-20's block 5. Don't paste it anywhere.
  • "the E2E organization is missing": BE-M0-29's seed didn't apply. Run its check, and paste the output of its block 4.
  • "system role … is missing": the seed migration isn't on staging. Paste the output of pnpm supabase migration list --linked.
  • A 4xx or 5xx error with a path: paste the line. Running block 2 again is safe: it keeps what exists and adds what's missing.
  • The check prints "error" for a role: that login didn't sign in. Run block 2 again, which sets every login's password to the one in .env.e2e, then the check. If it still fails, paste the check's output only.
  • A count differs from the list: paste the check's output. A role that prints 0 has a login without its role: run block 2 again.
  • The anon line prints a number instead of 42501: stop. A visitor reads drivers on staging. Paste the line; that is a bug in the grants, not something to fix on staging.

In the dashboard, Authentication › Users: search for e2e.opleet.test and delete the eleven logins. Each delete removes the login's profile, membership and roles with it. Or rebuild staging with BE-M0-33, which ends by making the logins again. .env.e2e stays as it is; the local logins use it too.

Log each run as a comment on #22: the date, block 2's last line, and the check's twelve lines. Never paste the password, a token, the secret key or anything else from .env.staging or .env.e2e.