From d15273e2a69e2416b81b470a8bd28f477fa30a42 Mon Sep 17 00:00:00 2001 From: denisireri Date: Tue, 13 Oct 2026 18:04:58 +0300 Subject: [PATCH] Send platform operators to the platform console after sign-in The operator account is the owner of a placeholder business, so sign-in landed it on that business's empty dashboard with a "Create your first branch" nudge. Operators now land on /platform (sign-in and the root page), the dashboard header says "Platform operator", and the nudge is hidden on the operator's own business. Co-Authored-By: Claude Opus 5.5 --- src/app/admin/dashboard/page.tsx | 10 +++++++--- src/app/api/auth/login/route.ts | 4 +++- src/app/page.tsx | 4 +++- tests/account.test.ts | 13 +++++++++++++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/app/admin/dashboard/page.tsx b/src/app/admin/dashboard/page.tsx index 3cf0022..cce1363 100644 --- a/src/app/admin/dashboard/page.tsx +++ b/src/app/admin/dashboard/page.tsx @@ -113,7 +113,8 @@ export default function AdminDashboardPage() { } const scope: "global" | "branch" = selectedBranchId === "ALL" ? "global" : "branch"; - const showNoBranchesNudge = me.role === "SUPER_ADMIN" && branchesLoaded && branches.length === 0; + // The operator's own business is a placeholder; don't nudge it to set up branches. + const showNoBranchesNudge = me.role === "SUPER_ADMIN" && !me.isPlatformAdmin && branchesLoaded && branches.length === 0; return (
@@ -130,7 +131,10 @@ export default function AdminDashboardPage() { ? `${me.branchName} Dashboard` : "Branch Dashboard"} -

{me.name}

+

+ {me.name} + {me.isPlatformAdmin && " ยท Platform operator"} +

@@ -142,7 +146,7 @@ export default function AdminDashboardPage() { onChange={setSelectedBranchId} isSuperAdmin={me.role === "SUPER_ADMIN"} /> -{me.isPlatformAdmin && ( + {me.isPlatformAdmin && ( Platform diff --git a/src/app/api/auth/login/route.ts b/src/app/api/auth/login/route.ts index b6da50b..2fe2d10 100644 --- a/src/app/api/auth/login/route.ts +++ b/src/app/api/auth/login/route.ts @@ -167,7 +167,9 @@ export async function POST(req: NextRequest) { phoneNumber: user.phoneNumber, email: user.email, }, - redirectTo: user.role === "DELIVERY" ? "/terminal" : "/admin/dashboard", + // Platform operators start on the console for every business, not on + // their own (placeholder) business's dashboard. + redirectTo: isPlatformAdmin(user) ? "/platform" : user.role === "DELIVERY" ? "/terminal" : "/admin/dashboard", isPlatformAdmin: isPlatformAdmin(user), }); diff --git a/src/app/page.tsx b/src/app/page.tsx index c6b4fad..5919042 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -12,7 +12,9 @@ export default function RootPage() { (async () => { try { const result = await apiFetch<{ user: AuthUser }>("/api/auth/me"); - if (result.user.role === "DELIVERY") { + if (result.user.isPlatformAdmin) { + router.replace("/platform"); + } else if (result.user.role === "DELIVERY") { router.replace("/terminal"); } else { router.replace("/admin/dashboard"); diff --git a/tests/account.test.ts b/tests/account.test.ts index c1f4aff..ca1096e 100644 --- a/tests/account.test.ts +++ b/tests/account.test.ts @@ -132,3 +132,16 @@ describe("moving staff between branches", () => { expect((await move(t.owner, t.branchB)).status).toBe(404); }); }); + +describe("where sign-in lands", () => { + it("sends the platform operator to the platform console, owners to the dashboard, cashiers to the till", async () => { + const t = await makeTenant(); + await Promise.all([setPassword(t.owner, "owner-pass"), setPassword(t.cashierA, "cashier-pass")]); + expect((await json(await signIn(t.owner, "owner-pass"))).body.redirectTo).toBe("/admin/dashboard"); + expect((await json(await signIn(t.cashierA, "cashier-pass"))).body.redirectTo).toBe("/terminal"); + + await db(() => User.updateOne({ _id: t.owner.id }, { email: "operator@aquaflow.test", platformAdmin: true })); + const operator = { ...t.owner, email: "operator@aquaflow.test" }; + expect((await json(await signIn(operator, "owner-pass"))).body.redirectTo).toBe("/platform"); + }); +}); -- 2.52.0