Files
Convivo/docs/frontend/api-client.md
T
ffb270c140 Registration optionset + speaker auto-promote + welcome check-in
- registrations.type is now a Postgres ENUM (registration_type)
- session_speakers trigger auto-promotes attendee -> speaker (never overrides staff/sponsor)
- new welcome_checkin RPC: staff marks an attendee present at the event
- admin Registrations: QR token is final (no reset); failed sponsor change opens in-place sponsor lookup
- Convivo Home: Now/Next cards always render; red pending-material pill + popup for speakers
- Convivo Agenda: speakers can delete their material to re-upload
- Convivo Scan: staff Session/Welcome check-in toggle (uiverse switch)
- seed: staff (Bruno/Rita) get a password so staff QR login works after reset

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
2026-08-23 21:33:44 +02:00

5.7 KiB

API Client

How the app talks to Supabase. Source: apps/convivo/src/lib/supabase.ts and apps/convivo/src/lib/api.ts.

The Supabase client (lib/supabase.ts)

const url = import.meta.env.VITE_SUPABASE_URL || window.location.origin;
const anonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;

export const supabase = createClient(url, anonKey, {
  auth: { persistSession: true, autoRefreshToken: true, detectSessionInUrl: false },
  realtime: { params: { eventsPerSecond: 10 } },
});
  • Same-origin by default. VITE_SUPABASE_URL is intentionally left unset, so the client uses window.location.origin. The app is served behind a proxy (Vite dev server, or nginx in Docker) that forwards /auth, /rest, /realtime, /storage to the Supabase core. This avoids CORS entirely. See ../backend/docker.md.
  • Anon key only. The client is created with the anon key (public). The user's identity comes from the session JWT, and RLS enforces access. See ../backend/rls.md.
  • Session persistence — the session is stored in localStorage and auto-refreshed, so a reload keeps you logged in. The JWT expiry is 24h (jwt_expiry = 86400), so a login lasts a full day.

The typed wrapper (lib/api.ts)

A thin, typed layer over supabase.rpc and supabase.from. It centralizes error handling (wraps Supabase errors in ApiError) and gives every screen a clean async API.

RPC calls (mutations + complex reads)

These map 1:1 to the Postgres RPCs documented in ../backend/rpcs.md:

Client function RPC Purpose
lanyardLookup(qrToken) lanyard_lookup Resolve a scanned QR to a public contact + registration type
getPublicContacts() get_public_contacts Active-event contact directory (names + types)
getAgenda() get_agenda Slots + sessions (flat rows)
getActiveEvent() get_active_event The active event row
setPreference(sessionId) set_preference Pick a session for its slot
clearPreference(slotId) clear_preference Remove a pick
createConnectionRequest(targetQr) create_connection_request Send a connection request
acceptConnection(id) accept_connection Accept (+5 to both)
rejectConnection(id) reject_connection Decline
checkinAttendee(sessionId, attendeeQr) checkin_attendee Staff session check-in (+10)
welcomeCheckin(attendeeQr) welcome_checkin Staff welcome check-in (marks present at event, no points)
submitFeedback(sessionId, rating, comment) submit_feedback Rate a session (+5/+10)
getLeaderboard() get_leaderboard Active-event leaderboard
uploadSessionMaterial(sessionId, file) set_session_material Upload to materials bucket + set material_path
removeSessionMaterial(sessionId) set_session_material Delete storage object + clear material_path (speakers)
updateMyProfile({linkedin_url, show_email, show_linkedin}) update_my_profile Self-service: set LinkedIn + visibility toggles on the caller's own contact

Direct table reads (RLS-scoped)

These read the caller's own rows (RLS returns only what the user may see). For an admin contact, RLS returns all rows, so the "my" reads filter by email client-side to avoid leaking other people's data:

Client function Table Returns
getMyContact(email) contacts the caller's contact
getMyRegistration(email) registrations the caller's registration (active event)
getMyPreferences() preferences the caller's picks
getMyConnections() connections connections the caller is in
getMyCheckins(email) checkins the caller's checked-in session ids
getMyFeedback(email) feedback the caller's feedback
getMyPointsLog(email) points_log the caller's points history
getMySpeakerSessions(email) session_speakers session ids the caller speaks

Helpers

  • groupAgenda(rows) — turns the flat get_agenda() rows into { slot, sessions[] }[] ordered by slot id. Used by useEvent().
  • sessionMaterialUrl(path) — builds the public URL for a session material in the materials bucket.

Types (lib/types.ts)

TypeScript interfaces mirroring the DB tables and RPC return shapes (Contact, Registration, Event, Slot, Session, AgendaRow, Preference, Connection, Checkin, Feedback, LeaderboardRow, PointsLogRow, PublicContact, CheckinResult, FeedbackResult). PublicContact is the safe projection (email + name + visibility-respected linkedin + registration type) returned by the public read functions.

Error handling

  • rpc() throws ApiError with the Postgres message on failure.
  • Screens catch errors and surface them via toasts (useToast().toast(message, 'err')). RPCs raise human-readable messages (e.g. "staff or admin only", "you must be checked in to this session to give feedback", "not a speaker of this session") — see ../backend/rpcs.md#error-handling.

Realtime + polling