feat: implement internal auth user creation and update related functionalities
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
# 0010 - Internal Auth User Creation
|
||||
|
||||
SQL file:
|
||||
|
||||
`supabase/migrations/0010_allow_internal_auth_user_creation.sql`
|
||||
|
||||
## Purpose
|
||||
|
||||
Allows Neta's trusted server-side flows to create Auth users after public registration is locked.
|
||||
|
||||
This is required for client portal accounts. Public signup remains blocked after the first admin account, but the application can create internal users through the service role key.
|
||||
|
||||
## Changes
|
||||
|
||||
- Adds `neta_internal.internal_auth_creations`.
|
||||
- Adds `public.request_internal_auth_creation(target_email, target_reason)`.
|
||||
- Grants that RPC only to `service_role`.
|
||||
- Updates `public.handle_new_user()` so it accepts a short-lived internal creation request.
|
||||
- Reloads the PostgREST schema cache.
|
||||
|
||||
## Operational Notes
|
||||
|
||||
The application calls the RPC immediately before calling the Supabase Auth Admin API. The pending request expires after two minutes and is consumed by the Auth user trigger.
|
||||
@@ -13,6 +13,7 @@ This file is the canonical order of SQL files for database setup and migration.
|
||||
| 0007 | `supabase/migrations/0007_add_client_portal_tables.sql` | `docs/database/0007-client-portal-tables.md` | Pending execution |
|
||||
| 0008 | `supabase/migrations/0008_add_project_progress_and_quota.sql` | `docs/database/0008-project-progress-and-quota.md` | Pending execution |
|
||||
| 0009 | `supabase/migrations/0009_lock_registration_after_first_admin.sql` | `docs/database/0009-lock-registration-after-first-admin.md` | Pending execution |
|
||||
| 0010 | `supabase/migrations/0010_allow_internal_auth_user_creation.sql` | `docs/database/0010-internal-auth-user-creation.md` | Pending execution |
|
||||
| seed-0001 | `supabase/seeds/0001_demo_freelancer_os_data.sql` | `docs/database/seed-0001-demo-freelancer-os-data.md` | Optional demo seed, pending execution |
|
||||
|
||||
## How To Add The Next Query
|
||||
@@ -37,4 +38,4 @@ Use the migration helper from the repository root:
|
||||
DATABASE_URL='postgresql://postgres:password@host:5432/postgres' sh ./scripts/apply-migrations.sh
|
||||
```
|
||||
|
||||
The helper applies missing queries from `0001` through `0009` in the order listed above and records completed migrations in `neta_internal.schema_migrations`. It uses local `psql` when available, otherwise it runs `psql` through Docker. After migrations, it sends `NOTIFY pgrst, 'reload schema'` so PostgREST can see new RPC functions without a manual restart.
|
||||
The helper applies missing queries from `0001` through `0010` in the order listed above and records completed migrations in `neta_internal.schema_migrations`. It uses local `psql` when available, otherwise it runs `psql` through Docker. After migrations, it sends `NOTIFY pgrst, 'reload schema'` so PostgREST can see new RPC functions without a manual restart.
|
||||
|
||||
Reference in New Issue
Block a user