Reads the session cookie from next/headers, verifies via auth-cookie, loads the operators row, returns the shape every existing call site expects (.id, .defaultTimezone, etc) plus the new .role and .username. getSeededOperator stays as a thin compat shim that delegates to getCurrentUser, so the ~12 tests that mock @/lib/operator keep working without churn.
22 lines
686 B
TypeScript
22 lines
686 B
TypeScript
import "server-only";
|
|
import { getCurrentUser } from "./auth";
|
|
|
|
/**
|
|
* Compatibility shim. The app used to seed a single operator and
|
|
* attribute everything to it; now we have real auth + roles. Existing
|
|
* call sites read `.id` and `.defaultTimezone` off the returned
|
|
* object — both are still present on the AuthUser shape, so the
|
|
* swap is mechanical and existing tests that mock @/lib/operator
|
|
* keep working unchanged.
|
|
*
|
|
* New code should call getCurrentUser / requireUser / requireAdmin
|
|
* from @/lib/auth directly.
|
|
*/
|
|
export async function getSeededOperator() {
|
|
const u = await getCurrentUser();
|
|
if (!u) {
|
|
throw new Error("Not authenticated");
|
|
}
|
|
return u;
|
|
}
|