024c882e09
GRO-153: /api/staff returned 403 for all staff because resolveStaffMiddleware looked up by staff.userId (Better-Auth ID) but dev login sent staff.id (PK), and existing staff records had userId=NULL. Changes: - resolveStaffMiddleware: try userId first, fall back to staff.id (dev mode) - resolveStaffMiddleware: try userId first, fall back to oidcSub (production) - GET /api/dev/users: include userId field for DevLoginSelector - DevLoginSelector: send userId (not staff.id) as X-Dev-User-Id - Migration 0018: backfill userId for known demo staff Co-authored-by: groombook-engineer[bot] <groombook-engineer@users.noreply.github.com> Co-authored-by: Paperclip <noreply@paperclip.ing> Co-authored-by: Barkley Trimsworth <barkley@groombook.farh.net>
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { Hono } from "hono";
|
|
import { getDb, staff, clients, eq, sql } from "@groombook/db";
|
|
|
|
const devRouter = new Hono();
|
|
|
|
// GET /api/dev/config — tells the frontend whether auth is disabled
|
|
devRouter.get("/config", (c) => {
|
|
return c.json({ authDisabled: process.env.AUTH_DISABLED === "true" });
|
|
});
|
|
|
|
// GET /api/dev/users — list staff and clients for the login selector
|
|
// Only available when AUTH_DISABLED=true
|
|
devRouter.get("/users", async (c) => {
|
|
if (process.env.AUTH_DISABLED !== "true") {
|
|
return c.json({ error: "Not available when auth is enabled" }, 403);
|
|
}
|
|
|
|
const db = getDb();
|
|
|
|
const staffList = await db
|
|
.select({
|
|
id: staff.id,
|
|
userId: staff.userId,
|
|
name: staff.name,
|
|
email: staff.email,
|
|
role: staff.role,
|
|
})
|
|
.from(staff)
|
|
.where(eq(staff.active, true))
|
|
.orderBy(staff.name);
|
|
|
|
const clientList = await db
|
|
.select({
|
|
id: clients.id,
|
|
name: clients.name,
|
|
email: clients.email,
|
|
petCount: sql<number>`(SELECT count(*) FROM pets WHERE pets.client_id = ${clients.id})`.as("pet_count"),
|
|
})
|
|
.from(clients)
|
|
.orderBy(clients.name)
|
|
.limit(20);
|
|
|
|
return c.json({ staff: staffList, clients: clientList });
|
|
});
|
|
|
|
export { devRouter };
|