Phase 2: Admin console (admin.appe.at)
A desktop-first React app for organizers, guarded to the admin role. Backend (supabase/migrations/20260823000000_admin_app.sql): - Admin-only SELECT policies on preferences, connections, feedback - reset_qr_token RPC: regenerates a lanyard token, re-hashes it as the Auth password (old token stops working), and clears the attendee's sessions to force re-login App (apps/admin, port 3001): - Login: same QR+email flow, but non-admin sessions are rejected - Dashboard: live stats + top points + recent activity - Attendees: search, edit name/company/role, reset QR, adjust points - Schedule: manage slots + sessions (create/edit/delete) - Activity: check-ins / connections / feedback tables - Same-origin proxy (Vite dev / nginx in Docker), same design tokens Docker + scripts: - convivo-admin service in docker-compose.yml (:3001) - admin:dev / admin:build root scripts - fixed db:reset script (supabase reset -> supabase db reset) Docs: new frontend/admin-app.md; updated architecture, rls, rpcs, docker, next-steps, and READMEs. Verified: build clean, all views + flows browser-tested, Docker build + proxy + login + admin guard confirmed. DB reset to clean seed.
This commit is contained in:
1 parent
0cbfb25714
commit
cf70f39903
45 files changed
+4425
-87
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import { supabase } from './supabase';
|
||||
import type {
|
||||
Checkin,
|
||||
Connection,
|
||||
Feedback,
|
||||
LeaderboardRow,
|
||||
PointsLogRow,
|
||||
Profile,
|
||||
ResetQrResult,
|
||||
Session,
|
||||
Slot,
|
||||
} from './types';
|
||||
|
||||
export class ApiError extends Error {}
|
||||
|
||||
async function rpc<T>(fn: string, args: Record<string, unknown>): Promise<T> {
|
||||
const { data, error } = await supabase.rpc(fn, args);
|
||||
if (error) throw new ApiError(error.message);
|
||||
return data as T;
|
||||
}
|
||||
|
||||
async function all<T>(table: string, order?: { col: string; asc?: boolean }): Promise<T[]> {
|
||||
let q = supabase.from(table).select('*');
|
||||
if (order) q = q.order(order.col, { ascending: order.asc ?? true });
|
||||
const { data, error } = await q;
|
||||
if (error) throw new ApiError(error.message);
|
||||
return data as T[];
|
||||
}
|
||||
|
||||
// ---- Reads (admin can read all rows via RLS) --------------------------------
|
||||
|
||||
export const getAllProfiles = () => all<Profile>('profiles', { col: 'points', asc: false });
|
||||
export const getAllSlots = () => all<Slot>('slots', { col: 'id' });
|
||||
export const getAllSessions = () => all<Session>('sessions', { col: 'slot_id' });
|
||||
export const getAllConnections = () => all<Connection>('connections', { col: 'created_at', asc: false });
|
||||
export const getAllCheckins = () => all<Checkin>('checkins', { col: 'created_at', asc: false });
|
||||
export const getAllFeedback = () => all<Feedback>('feedback', { col: 'created_at', asc: false });
|
||||
export const getAllPointsLog = () => all<PointsLogRow>('points_log', { col: 'created_at', asc: false });
|
||||
export const getLeaderboard = () => all<LeaderboardRow>('leaderboard', { col: 'points', asc: false });
|
||||
|
||||
// ---- Writes (admin only) ----------------------------------------------------
|
||||
|
||||
/** Update an attendee's editable fields (name, company, role). */
|
||||
export async function updateProfile(
|
||||
id: string,
|
||||
patch: { full_name?: string; company?: string | null; role?: Profile['role'] },
|
||||
): Promise<void> {
|
||||
const { error } = await supabase.from('profiles').update(patch).eq('id', id);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
|
||||
/** Admin manual points adjustment (audited as 'admin'). */
|
||||
export async function adjustPoints(profileId: string, delta: number, reason: string): Promise<void> {
|
||||
await rpc('adjust_points', { p_profile_id: profileId, p_delta: delta, p_reason: reason });
|
||||
}
|
||||
|
||||
/** Regenerate an attendee's QR token (syncs the auth password, forces re-login). */
|
||||
export async function resetQrToken(profileId: string): Promise<ResetQrResult> {
|
||||
const rows = await rpc<ResetQrResult[]>('reset_qr_token', { p_profile_id: profileId });
|
||||
return rows[0];
|
||||
}
|
||||
Reference in new issue
Block a user