Add a 'Post User Creation' auth hook (or 'After User Creation') #39576
Replies: 3 comments 6 replies
-
|
Right now you have to use an auth.users trigger function to process after the row is created, or before depending on what all you need to do. I've seen an after hook one mentioned like they plan on it, but it is not available yet. |
Beta Was this translation helpful? Give feedback.
-
|
Although post user create hook is not available yet, we can still create post user create trigger, through Supabase CLI: For example, this is generated by Supabase MCP Then a trigger will be created in auth:
The
The database function can also call external API. We cannot create a trigger on auth in Supabase dashboard, but it can done through CLI. You might also want to create another migration, to backfill existing users. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for bringing this up. I currently use a database trigger to pass some values from the frontend into the user_profiles table and to randomly generate a username (with retry logic). It works, but I hate having that kind of logic inside the database. Glad to hear that a hook is coming. |
Beta Was this translation helpful? Give feedback.



Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
The
Before User Created Authhook is great when wanting full control of which users are created and which properties created users are going to have. However, they have a significant issue: it's impossible to insert data into the database that is directly linked to the user being created.The problem is straightforward: since the user hasn't been created yet, any foreign key integrity check will fail because there's no user entity to link to.
Proposal
Add another auth hook, which is triggered once the user is inserted into the database and which is awaited before returning successfully to
supabase.auth.signup(). That way, developers can set up the user's account properly on the backend side, and once the user is actually signed in on the frontend, everything is ready to use. ThePost User CreationorAfter User Creationauth hookExample usage
A new user is created, and now I have to seed a variety of tables in the database to initialize this user:
idin the auth's user tableMore context on database schema
My database schema is simple (and probably analogous to most Supabase DB schemas). I have a
user_profilewith anid(primary key) and auser_id(foreign key to auth'suser.id. I use theuser_profile.user_idin almost every other table throughout my database as a reference. This way, I can minimize RLS merges since theuser_idin every table matches the one in auth'suser.id. At the same time, this approach gives me full flexibility. I can simply replace the reference inuser_profile.user_idwith auth'suser.id, and with that change, all my data becomes independent of the internal Supabase data schemas.My
user_profiletable includes properties such asdemo_finishedto track user progress and other attributes that don't fit within Supabase's default authentication schema. Since transitively most tables depend on the auth'suser.idthrough a foreign key relationship, it is not possible to do any of these initialization operations in theBefore User Created Authhook!Beta Was this translation helpful? Give feedback.
All reactions