-- ============================================================================= -- Convivo — Admin password + attendee profile self-service -- -- 1. `contacts.password` — an admin-only property: the admin's APPE Admin login -- password. It is independent of the per-event QR token, so an admin can log -- into APPE Admin at any time, regardless of the active event. -- -- NOTE: Supabase Auth has a single password per user -- (`auth.users.encrypted_password`). For `contacts.password` to work as the -- APPE Admin login, the matching `auth.users.encrypted_password` must be its -- bcrypt hash. Admins set both directly in Supabase (no self-service UI in -- v1). The seed gives the dedicated admin a demo password in both places. -- -- 2. `update_my_profile` — lets a signed-in attendee update their OWN contact -- row: LinkedIn URL + the two visibility toggles (show_email / show_linkedin). -- Scoped to the caller (`current_email()`); only those three columns are -- writable, so it can't touch `is_admin`, `password`, etc. -- ============================================================================= -- ----------------------------------------------------------------------------- -- 1. ADMIN PASSWORD (admin-only property on the contact) -- ----------------------------------------------------------------------------- alter table public.contacts add column if not exists password text; comment on column public.contacts.password is 'Admin-only: the APPE Admin login password (event-independent). To work it must ' 'match the bcrypt hash in auth.users.encrypted_password. Set directly in Supabase.'; -- ----------------------------------------------------------------------------- -- 2. UPDATE MY PROFILE (attendee self-service: LinkedIn + visibility) -- ----------------------------------------------------------------------------- create or replace function public.update_my_profile( p_linkedin_url text, p_show_email boolean, p_show_linkedin boolean ) returns public.contacts language plpgsql security definer set search_path = public as $$ declare v_email text := public.current_email(); v_contact public.contacts; begin if v_email is null then raise exception 'not authenticated'; end if; update public.contacts set linkedin_url = case when p_linkedin_url is null or btrim(p_linkedin_url) = '' then null else btrim(p_linkedin_url) end, show_email = coalesce(p_show_email, false), show_linkedin = coalesce(p_show_linkedin, false) where email = v_email returning * into v_contact; if not found then raise exception 'contact not found'; end if; return v_contact; end; $$; grant execute on function public.update_my_profile(text, boolean, boolean) to authenticated;