feat(supabase): auth, profile and roles services; professional columns on profiles; OAuth + TOTP config

- packages/supabase: signIn/signUp/OAuth/reset/updatePassword/signOut wrappers with a closed AuthFailure kind, fetch/update own profile, own platform roles
- migration 20261011100000: practice_name, professional_title, siret (format-checked, column grants); pgTAP 009; database.types regenerated
- config.toml: TOTP enroll/verify on, [auth.external.google|apple] via env(), wildcard redirect URLs
- app config: authProviders (APP_AUTH_PROVIDERS / VITE_AUTH_PROVIDERS), entrypoint env.js, DEPLOY table
- TODO: Step 7 plan
This commit is contained in:
bchanot committed 2026-10-11 23:16:13 +02:00
1 parent c746952d7f
commit b10b227ee9
13 files changed
+427 -10

No files matched your search

+25 -4
View File
@@ -69,7 +69,12 @@ enabled = false
enabled = true
# Vite dev server of apps/app
site_url = "http://127.0.0.1:5173"
additional_redirect_urls = ["http://127.0.0.1:5173", "http://localhost:5173"]
additional_redirect_urls = [
"http://127.0.0.1:5173",
"http://localhost:5173",
"http://127.0.0.1:5173/**",
"http://localhost:5173/**",
]
jwt_expiry = 3600
enable_refresh_token_rotation = true
refresh_token_reuse_interval = 10
@@ -107,9 +112,25 @@ enable_confirmations = false
max_enrolled_factors = 10
[auth.mfa.totp]
# Enrolment opens with the identity step (mandatory for platform staff).
enroll_enabled = false
verify_enabled = false
# Server side ready since Step 7; the enrolment UI and the has_mfa() helper
# enforcing it for platform staff are still to come (SUPABASE.md §11).
enroll_enabled = true
verify_enabled = true
# OAuth providers (Step 7). Values come from the environment: the CLI reads
# supabase/.env (gitignored) or the shell. Disabled until the ids exist.
# Google: https://supabase.com/docs/guides/auth/social-login/auth-google
[auth.external.google]
enabled = false
client_id = "env(SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_ID)"
secret = "env(SUPABASE_AUTH_EXTERNAL_GOOGLE_SECRET)"
skip_nonce_check = false
# Apple needs a paid developer account + a Services ID (BACKEND_ARCHITECTURE §2).
[auth.external.apple]
enabled = false
client_id = "env(SUPABASE_AUTH_EXTERNAL_APPLE_CLIENT_ID)"
secret = "env(SUPABASE_AUTH_EXTERNAL_APPLE_SECRET)"
[edge_runtime]
# No Edge Function before the files/webhooks steps; keeps the local stack light.
@@ -0,0 +1,23 @@
-- Step 7 identity: professional information on the account profile.
-- Free text declared by the practitioner, shown in "Mon compte". Verification
-- (SIRET check, documents, badge) belongs to the Professional Verification
-- domain (DOMAIN_MAP §2) and lands with its own tables; nothing here is trusted.
alter table public.profiles
add column practice_name text
constraint profiles_practice_name_length check (char_length(practice_name) between 1 and 120),
add column professional_title text
constraint profiles_professional_title_length check (char_length(professional_title) between 1 and 80),
-- French SIRET: 14 digits, format only (no Luhn, no registry lookup).
add column siret text
constraint profiles_siret_format check (siret ~ '^[0-9]{14}$');
comment on column public.profiles.practice_name is
'Cabinet / practice name declared by the user. Unverified.';
comment on column public.profiles.professional_title is
'Professional title declared by the user (e.g. ostéopathe animalier). Unverified.';
comment on column public.profiles.siret is
'SIRET declared by the user, 14 digits, format-checked only. Verification = later domain.';
-- Same rule as the other user-editable columns: column-level UPDATE, own row through RLS.
grant update (practice_name, professional_title, siret) on public.profiles to authenticated;
@@ -0,0 +1,72 @@
-- Professional columns on profiles: own-row update, format checks, denied paths.
begin;
select plan(13);
insert into auth.users (id, email) values
('00000000-0000-0000-0000-00000000000a', 'alice@test.local'),
('00000000-0000-0000-0000-00000000000b', 'bob@test.local');
select has_column('public', 'profiles', 'practice_name', 'practice_name exists');
select has_column('public', 'profiles', 'professional_title', 'professional_title exists');
select has_column('public', 'profiles', 'siret', 'siret exists');
select is(
(select count(*)::int from information_schema.column_privileges
where table_schema = 'public' and table_name = 'profiles' and grantee = 'authenticated'
and privilege_type = 'UPDATE'
and column_name in ('practice_name', 'professional_title', 'siret')),
3,
'authenticated may update the three professional columns'
);
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
select lives_ok(
$$ update public.profiles
set practice_name = 'Cabinet Équilibre', professional_title = 'Ostéopathe animalier', siret = '12345678901234'
where id = '00000000-0000-0000-0000-00000000000a' $$,
'alice fills her professional information'
);
select is(
(select siret from public.profiles where id = '00000000-0000-0000-0000-00000000000a'),
'12345678901234',
'siret stored as declared'
);
select throws_ok(
$$ update public.profiles set siret = '1234' where id = '00000000-0000-0000-0000-00000000000a' $$,
'23514', null, 'siret must be 14 digits'
);
select throws_ok(
$$ update public.profiles set siret = '1234567890123a' where id = '00000000-0000-0000-0000-00000000000a' $$,
'23514', null, 'siret refuses letters'
);
select throws_ok(
$$ update public.profiles set practice_name = '' where id = '00000000-0000-0000-0000-00000000000a' $$,
'23514', null, 'empty practice_name refused (null clears it)'
);
select lives_ok(
$$ update public.profiles set siret = null, practice_name = null where id = '00000000-0000-0000-0000-00000000000a' $$,
'alice clears her professional information'
);
-- Bob's row is invisible to alice: the update touches zero rows.
select is(
(select count(*)::int from public.profiles where id = '00000000-0000-0000-0000-00000000000b'),
0,
'alice does not see bob'
);
select lives_ok(
$$ update public.profiles set practice_name = 'Hijack'
where id = '00000000-0000-0000-0000-00000000000b' $$,
'writing an invisible row raises nothing'
);
reset role;
select is(
(select practice_name from public.profiles where id = '00000000-0000-0000-0000-00000000000b'),
null,
'bob untouched'
);
select * from finish();
rollback;