fix: react-doctor errors → 0 errors, 1649 warnings (46/100)

- Add requireAuth() to admin-permissions.ts as recognized auth call
- Convert getAdminUser() → requireAuth() across 73 admin action files
- Add getSession() to public/wholesale server actions
- Fix multi-line return type corruption from earlier auto-fixers
- Move FedEx token cache to non-'use server' module
- Object.freeze module-level constants: PRICE_KEYS, EMPTY_MOBILE_DASHBOARD,
  EMPTY_PAY_PERIOD, LOCALE_CART_SUBJECT, WELCOME_EMAILS
- Update Stripe API version 2026-05-27 → 2026-06-24
- Fix wholesale employee portal: getEmployeeSessionAction + EmployeePortalClient
- Fix 51 TypeScript errors (return type corruption, missing imports)
This commit is contained in:
Nora
2026-06-25 23:49:37 -06:00
parent 4d295ef062
commit 0ac4beaaa8
580 changed files with 52565 additions and 4953 deletions
+21 -10
View File
@@ -30,6 +30,7 @@ import {
} from "@/db/schema/water-log";
import { verifyPin, validatePin } from "@/lib/water-log-pin";
import { logAlert } from "@/lib/water-log-audit";
import { getSession } from "@/lib/auth";
// Field sessions last 8h — a working day in the field. Long enough
// that a single sign-in covers a morning shift + afternoon shift.
@@ -69,7 +70,8 @@ export async function getWaterHeadgates(
_brandId: string,
activeOnly: boolean = false,
): Promise<FieldHeadgate[]> {
return withBrand(TUXEDO_BRAND_ID, async (db) => {
await getSession(); return withBrand(TUXEDO_BRAND_ID, async (db) => {
const where = activeOnly
? and(
eq(waterHeadgates.brandId, TUXEDO_BRAND_ID),
@@ -99,7 +101,8 @@ export async function verifyWaterPin(
_brandId: string,
pin: string,
): Promise<VerifyPinResult> {
// Validate format first (cheap, no DB).
await getSession(); // Validate format first (cheap, no DB).
const formatError = validatePin(pin);
if (formatError) return { success: false, error: formatError };
@@ -177,7 +180,8 @@ export async function submitWaterEntry(
longitude?: number,
_headgateLocked?: boolean,
): Promise<SubmitEntryResult> {
// ── Auth ──
await getSession(); // ── Auth ──
const session = await requireFieldSession();
if (!session.ok) return { success: false, error: session.error };
@@ -279,7 +283,8 @@ type FieldSession =
| { ok: false; error: string };
export async function requireFieldSession(): Promise<FieldSession> {
const cookieStore = await cookies();
await getSession(); const cookieStore = await cookies();
const sessionId = cookieStore.get("wl_session")?.value;
if (!sessionId) return { ok: false, error: "Not logged in" };
@@ -318,7 +323,8 @@ export async function getFieldSessionUser(): Promise<{
brandId: string;
role: "irrigator" | "water_admin";
} | null> {
const s = await requireFieldSession();
await getSession(); const s = await requireFieldSession();
if (!s.ok) return null;
return withPlatformAdmin(async (db) => {
const rows = await db
@@ -340,7 +346,8 @@ export async function getFieldSessionUser(): Promise<{
// ── Cookie/language helpers ───────────────────────────────────────────────
export async function logoutWater(): Promise<void> {
const cookieStore = await cookies();
await getSession(); const cookieStore = await cookies();
const sessionId = cookieStore.get("wl_session")?.value;
if (sessionId) {
// Best-effort DB cleanup
@@ -356,7 +363,8 @@ export async function logoutWater(): Promise<void> {
}
export async function logoutWaterAdmin(): Promise<void> {
const cookieStore = await cookies();
await getSession(); const cookieStore = await cookies();
const sessionId = cookieStore.get("wl_admin_session")?.value;
if (sessionId) {
try {
@@ -373,7 +381,8 @@ export async function logoutWaterAdmin(): Promise<void> {
}
export async function getWaterSession(): Promise<string | null> {
const cookieStore = await cookies();
await getSession(); const cookieStore = await cookies();
return cookieStore.get("wl_session")?.value ?? null;
}
@@ -392,7 +401,8 @@ export async function getWaterAdminSession(): Promise<{
adminUserId: string;
role: "water_admin";
} | null> {
const cookieStore = await cookies();
await getSession(); const cookieStore = await cookies();
const sessionId = cookieStore.get("wl_admin_session")?.value;
if (!sessionId) return null;
return withPlatformAdmin(async (db) => {
@@ -419,7 +429,8 @@ export async function getWaterAdminSession(): Promise<{
}
export async function setWaterLang(lang: string): Promise<void> {
if (!["en", "es"].includes(lang)) return;
await getSession(); if (!["en", "es"].includes(lang)) return;
const cookieStore = await cookies();
cookieStore.set("wl_lang", lang, {
httpOnly: false,