From d869b7860ce22a5ce480b73b9fc154d42bdfa7cb Mon Sep 17 00:00:00 2001
From: sahajiscoding <135018977+sahajiscoding@users.noreply.github.com>
Date: Thu, 5 Nov 2026 15:19:32 +0000
Subject: [PATCH 1/2] feat: offer isolated demo access alongside Supabase login
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
---
.github/workflows/ci.yml | 3 +
PROJECT_STATUS.md | 20 +-
apps/admin/package.json | 9 +-
apps/admin/src/App.tsx | 6 +-
apps/admin/src/components/AppShell.tsx | 15 +-
apps/admin/src/contexts/AuthContext.tsx | 66 +-
apps/admin/src/lib/appData.tsx | 5 +-
apps/admin/src/lib/demo.ts | 34 +
apps/admin/src/lib/supabase.ts | 3 +-
apps/admin/src/pages/Login.tsx | 108 +--
apps/admin/tests/demo.test.tsx | 77 ++
apps/admin/tests/live-login.test.tsx | 50 ++
apps/admin/vitest.config.ts | 15 +
docs/security/environment-variables.md | 19 +-
.../specs/2026-11-03-school-erp-design.md | 1 +
package-lock.json | 752 +++++++++++++++++-
16 files changed, 1091 insertions(+), 92 deletions(-)
create mode 100644 apps/admin/src/lib/demo.ts
create mode 100644 apps/admin/tests/demo.test.tsx
create mode 100644 apps/admin/tests/live-login.test.tsx
create mode 100644 apps/admin/vitest.config.ts
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 56aa58b..f7da316 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -29,6 +29,9 @@ jobs:
- run: npm run lint
+ - name: Test demo isolation and school login
+ run: npm run test --workspace=apps/admin
+
- name: Build admin console
run: npm run build --workspace=apps/admin
diff --git a/PROJECT_STATUS.md b/PROJECT_STATUS.md
index 61a975e..2a5c1c0 100644
--- a/PROJECT_STATUS.md
+++ b/PROJECT_STATUS.md
@@ -23,8 +23,8 @@ This file is the single source of truth for project state. Every agent must read
| Helpers | `src/lib/utils.ts` | Dates, INR, CSV parser, `normalizeDob` (rejects 31 Feb), `passwordFromDob`, `gradeFor`, `printHtml` |
| Supabase client | `src/lib/supabase.ts` | Reads `SUPABASE_URL` / `SUPABASE_PUBLISHABLE_KEY`; `configHint()` names the missing pair |
| Build config | `vite.config.ts` | `loadEnv(mode, cwd, '')` so **unprefixed** `SUPABASE_URL` works from `.env`; inlines both names via `define` |
-| Login | `src/pages/Login.tsx` | School design; small passwordless **"Try a demo"** button (Admin / Teacher / Student picker, demo mode only); remembered account |
-| Demo entry | `src/contexts/AuthContext.tsx` | `signInAsDemo(role)` signs in as the seeded person for the role; refused whenever a Supabase client exists; no credentials anywhere in the client |
+| Login | `src/pages/Login.tsx` | School design; always-visible **"Try a demo"** button (Admin / Teacher / Student), including with Supabase configured; remembered account |
+| Demo entry | `src/contexts/AuthContext.tsx` | `signInAsDemo(role)` opens isolated `/demo` with a seeded role; `src/lib/demo.ts` defines the route boundary; no Supabase client is created inside `/demo` |
### Dashboard modules
@@ -61,7 +61,7 @@ This file is the single source of truth for project state. Every agent must read
| Admin bootstrap | `scripts/create-admin.mjs` | Local-only, service role from environment |
| CI | `.github/workflows/ci.yml` | Rewritten (the committed file was a single line of literal `\n`): typecheck, lint, build, secret guard, env-name guard |
-### Demo entry + credential removal (2026-11-05)
+### Original demo entry + credential removal (2026-11-05; visibility restriction superseded below)
- Login page has a small "Try a demo" button that expands into Admin / Teacher / Student options; one click enters that role's dashboard with no login. Shown only in demo mode (no Supabase configured); `signInAsDemo` refuses when a Supabase client exists, so the client never decides identity against a live backend.
- Demo teacher display name is now **Teacher** (seed profile, sample notification, and teaching-assignment sample row). Existing `v3` demo data migrates to `v4` without resetting other demo edits. Verified: admin typecheck/lint/build clean; 39 role smoke checks and 6 storage-migration checks pass; production bundle contains no old display name.
@@ -70,6 +70,20 @@ This file is the single source of truth for project state. Every agent must read
- The school's `Student@DDMMYYYY` initial-password rule is unchanged — it is derived from DOB at runtime (`utils.ts`, `admin-users` Edge Function), never stored as a literal.
- Verified: admin + shared typecheck clean; eslint 0 errors; production build passes; `grep` of `dist/assets/*.js` finds zero credential strings and the demo button ships in the bundle (works on a deployed demo-mode build). jsdom smoke test clicked through all three roles: correct seeded identity, role-aware nav, sign-out returns to login — 39/39 checks pass.
+### Demo visibility investigation (2026-11-05; before the fix below)
+
+- Read-only application/configuration review confirmed the demo picker exists in `apps/admin/src/pages/Login.tsx`, but renders only when `missingSupabaseConfig()` is true (`src/lib/supabase.ts`, `src/contexts/AuthContext.tsx`). Network unavailability does not enable demo mode; the presence of both public configuration values disables the picker.
+- Vercel metadata confirms the latest ready production deployment uses commit `29681ccca26a4af81602b2e072fe9018c5efe4fe` (the inspected source), and the project has `SUPABASE_URL` and `SUPABASE_PUBLISHABLE_KEY` configured for production. This explains the hidden production demo entry; no secrets were decrypted and no deployment/settings were changed. Live browser behaviour was not tested in this investigation.
+- The separate header **View as** control in `src/components/AppShell.tsx` is available only after signing in with an admin profile. Next: decide whether to offer a separate isolated demo deployment or implement an explicit isolated demo experience alongside live login; do not remove production authentication configuration to expose the picker.
+
+### Demo alongside configured Supabase (2026-11-05)
+
+- Owner requested demos on the configured production site without creating accounts. `apps/admin/src/pages/Login.tsx` now always offers **Try a demo → Admin / Teacher / Student**; the signed-in header also links to `/demo/login`. Live login remains visible while auth restoration is pending, so slow Supabase does not hide demo entry.
+- `src/lib/demo.ts`, `src/lib/supabase.ts`, `src/contexts/AuthContext.tsx`, and `src/App.tsx` isolate the showcase under `/demo` using full-page entry/exit and a separate router base. No Supabase client or live auth subscription is created there; backend session identity stays null. The seeded role survives refresh in tab-local storage. Invalid roles are rejected; demo sign-out does not sign out a real account.
+- `src/lib/appData.tsx` stores showcase edits separately (`pws.showcase.data.v1`), with no migration from the school-console store. `src/components/AppShell.tsx` displays a persistent sample-data banner and **Exit demo · School sign in**. Demo login never displays a remembered real account.
+- Added Vitest/jsdom regression tests under `apps/admin/tests/`, `vitest.config.ts`, the `test` workspace script, and a CI test step. Verified: 10 tests pass (all roles, configured Supabase, direct entry, refresh, sign-out, data/reset isolation, blocked storage, invalid roles, pending auth, normal password login); admin/shared typechecks pass; admin lint has 0 errors and 3 existing fast-refresh warnings; production build passes (bundle-size warning only).
+- Updated `docs/security/environment-variables.md` and the design decision log. No production environment variables, auth accounts, database policies, or deployments changed. Next: deploy this branch's changes to make the demo entry visible on the production site; keep future backend modules isolated from `/demo`.
+
### Verification done
- `npm run typecheck --workspace=apps/admin` — clean.
diff --git a/apps/admin/package.json b/apps/admin/package.json
index 662e3e8..62863ea 100644
--- a/apps/admin/package.json
+++ b/apps/admin/package.json
@@ -8,7 +8,8 @@
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview",
- "typecheck": "tsc -b --noEmit"
+ "typecheck": "tsc -b --noEmit",
+ "test": "vitest run"
},
"dependencies": {
"@schoolerp/shared": "*",
@@ -24,6 +25,8 @@
},
"devDependencies": {
"@eslint/js": "^10.0.0",
+ "@testing-library/react": "^16.3.3",
+ "@testing-library/user-event": "^14.6.8",
"@types/node": "^24.6.0",
"@types/react": "^19.1.16",
"@types/react-dom": "^19.1.9",
@@ -35,10 +38,12 @@
"eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-react-refresh": "^0.5.7",
"globals": "^16.4.0",
+ "jsdom": "^31.0.0",
"postcss": "^8.5.32",
"tailwindcss": "^3.4.19",
"typescript": "~5.9.3",
"typescript-eslint": "^8.45.0",
- "vite": "^7.1.7"
+ "vite": "^7.1.7",
+ "vitest": "^5.1.0"
}
}
diff --git a/apps/admin/src/App.tsx b/apps/admin/src/App.tsx
index 36ed3ae..6e23d69 100644
--- a/apps/admin/src/App.tsx
+++ b/apps/admin/src/App.tsx
@@ -1,6 +1,7 @@
import type { ReactNode } from 'react';
import { BrowserRouter, Navigate, Routes, Route, useLocation } from 'react-router-dom';
import { AuthProvider, useAuth } from './contexts/AuthContext';
+import { isDemoPath } from './lib/demo';
import { AppDataProvider } from './lib/appData';
import AppShell from './components/AppShell';
import Login from './pages/Login';
@@ -37,7 +38,8 @@ function RequireAuth({ children }: { children: ReactNode }) {
function GuestOnly({ children }: { children: ReactNode }) {
const { loading, profile } = useAuth();
- if (loading) return null;
+ // Demo entry must remain available while live auth is slow or offline.
+ if (loading) return <>{children}>;
return profile ? : <>{children}>;
}
@@ -57,7 +59,7 @@ export default function App() {
return (
-
+
Demo data
- Supabase keys are not set, so the console runs on the seeded school.
+ Sample data only. Changes stay in this browser and never affect school records.