- contacts.password: admin-only APPE Admin login password (event-independent); must match the bcrypt hash in auth.users.encrypted_password (set in Supabase). - APPE Admin login is now email + password (was QR token). - update_my_profile RPC (security definer, scoped to current_email()): attendees set their LinkedIn URL + show_email / show_linkedin toggles from the Profile. - Convivo Profile gains a 'Profile settings' card (LinkedIn + 2 toggles + Save). - Visibility enforced server-side in the public projection (linkedin nulled when show_linkedin off, email omitted when show_email off). - Seed: admin password appe-admin-2026; staff keep QR tokens as auth passwords. - Docs updated (schema, rpcs, seed, admin-app, screens, api-client, architecture, next-steps, README, docker-compose). 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]>
54 lines
2.7 KiB
PL/PgSQL
54 lines
2.7 KiB
PL/PgSQL
-- =============================================================================
|
|
-- 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;
|