d892b3f64f
Deploy to route.crispygoat.com / deploy (push) Failing after 9s
Phase 1 — Pattern library - Add src/lib/api.ts (typed PostgREST client, anon-key) - Add src/lib/svc-fetch.ts (service-role fetch + PostgREST client) - Add src/lib/db-types.ts (Database generic, RowOf helper) - Add src/lib/auth-admin.ts (better-auth admin wrappers: createUser, listUsers, removeUser, requestPasswordReset, validateSession) Phase 2 — Server action migration - Migrate all 67 server actions off @supabase/supabase-js to svcApi/svcRpc - Replace service.auth.admin.* with authAdmin.* (better-auth) - Replace publicApi.auth.* with authAdmin.* (better-auth) - Add typed single() null guards + nullable column fallbacks Phase 3 — Delete mock data + debug routes - Remove if(useMockData) branches from 7 files (-226 lines) - Delete src/lib/mock-data.ts (no longer referenced) - Delete 7 debug API routes (debug-admin-users, debug-auth, debug-cookie, debug-env, debug-get-admin-users, debug-hello, debug-me) Phase 4 — Hard cut - Delete src/lib/supabase.ts (orphan — no importers) - Delete src/app/api/supabase + src/app/api/supabase-test routes - Remove @supabase/ssr + @supabase/supabase-js from package.json - Rename env vars: NEXT_PUBLIC_SUPABASE_URL → NEXT_PUBLIC_API_URL, NEXT_PUBLIC_SUPABASE_ANON_KEY → NEXT_PUBLIC_API_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY → POSTGREST_SERVICE_KEY Phase 5 — Verify - npx tsc --noEmit: 0 errors - npm run lint: 0 new errors from migration (104 pre-existing errors unrelated) - npm run build: same failure mode as main worktree (PostgREST-dependent prerender), no regression Net: 158 files changed, +1640 / -1903 lines (-263 net)
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
"use server";
|
|
|
|
import { svcRpc } from "@/lib/svc-fetch";
|
|
|
|
type AdminActionPayload = {
|
|
action_type: "create" | "update" | "delete";
|
|
admin_id?: string;
|
|
admin_email?: string;
|
|
affected_user_id?: string;
|
|
brand_id?: string;
|
|
details?: Record<string, unknown>;
|
|
};
|
|
|
|
type UserActivityPayload = {
|
|
user_id: string;
|
|
activity_type: "login" | "logout" | "password_change" | "profile_update" | "email_change";
|
|
details?: Record<string, unknown>;
|
|
ip_address?: string;
|
|
user_agent?: string;
|
|
};
|
|
|
|
export async function logAdminAction(payload: AdminActionPayload): Promise<void> {
|
|
try {
|
|
await svcRpc("log_admin_action", {
|
|
p_payload: {
|
|
action_type: payload.action_type,
|
|
admin_id: payload.admin_id ?? null,
|
|
admin_email: payload.admin_email ?? null,
|
|
affected_user_id: payload.affected_user_id ?? null,
|
|
brand_id: payload.brand_id ?? null,
|
|
details: payload.details ?? {},
|
|
},
|
|
});
|
|
} catch (e) {
|
|
// logging failed silently
|
|
}
|
|
}
|
|
|
|
export async function logUserActivity(payload: UserActivityPayload): Promise<void> {
|
|
try {
|
|
await svcRpc("log_user_activity", {
|
|
p_payload: {
|
|
user_id: payload.user_id,
|
|
activity_type: payload.activity_type,
|
|
details: payload.details ?? {},
|
|
ip_address: payload.ip_address ?? null,
|
|
user_agent: payload.user_agent ?? null,
|
|
},
|
|
});
|
|
} catch (e) {
|
|
// logging failed silently
|
|
}
|
|
}
|