# Assigning user roles on registration - 2 roles, 2 registration forms (Supabase/Weweb)

**URL:** <https://community.weweb.io/t/assigning-user-roles-on-registration-2-roles-2-registration-forms-supabase-weweb/9330>\
**Category:** Ask us anything\
**Tags:** authentication, supabase\
**Created:** [June 25, 2024, 8:45am UTC](https://community.weweb.io/t/assigning-user-roles-on-registration-2-roles-2-registration-forms-supabase-weweb/9330 "2024-06-25T08:45:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![waq.war](https://avatars.discourse-cdn.com/v4/letter/w/0ea827/32.png) [@waq.war](https://community.weweb.io/u/waq.war)\
**Post date:** [June 25, 2024, 8:45am UTC](https://community.weweb.io/t/assigning-user-roles-on-registration-2-roles-2-registration-forms-supabase-weweb/9330/1 "2024-06-25T08:45:26Z")

</div>

Hi all - big fan of weweb/ supabase combo so far. everything has smooth sailing, but ive been stuck on this problem for a while

This project has 2 users roles (Advisors, Clients) with 2 dedicated registration forms.

Roles, UserRoles, UserProfile tables are all set up, which means its possible to manually allocate a User the correct role. My question is there a way to automate this? eg, When a user signs up through a Advisor-registration form/ Client-registration form, they are automatically assign those roles.

Considered a function/trigger in supabase to allocate role, but there seem to be no way to communicate which form the user registered from. I may be wrong, but this seems to indicate the workflow needs to be created on the app-side.

Any help/ pointers would be massively appreciated!

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [June 25, 2024, 10:38am UTC](https://community.weweb.io/t/assigning-user-roles-on-registration-2-roles-2-registration-forms-supabase-weweb/9330/2 "2024-06-25T10:38:06Z")

</div>

Hey, you could do this with metadata and triggers. You could do a workflow, where you define metadata, and a trigger that automatically based on that metadata adds a role/whatever you need to define. Or you could do a Postgres function. If you feel stuck, [I do 1:1 sessions where I do this kind of setups with people.](https://broberto.sk/consult)

---

<div class="post-metadata">

**Author:** ![waq.war](https://avatars.discourse-cdn.com/v4/letter/w/0ea827/32.png) [@waq.war](https://community.weweb.io/u/waq.war)\
**Post date:** [June 26, 2024, 9:03am UTC](https://community.weweb.io/t/assigning-user-roles-on-registration-2-roles-2-registration-forms-supabase-weweb/9330/3 "2024-06-26T09:03:15Z")

</div>

Thanks! the editors in maintenance right now, but give this route a try

will keep the 1:1 in mind for future

---

<div class="post-metadata">

**Author:** ![waq.war](https://avatars.discourse-cdn.com/v4/letter/w/0ea827/32.png) [@waq.war](https://community.weweb.io/u/waq.war)\
**Post date:** [June 27, 2024, 10:52am UTC](https://community.weweb.io/t/assigning-user-roles-on-registration-2-roles-2-registration-forms-supabase-weweb/9330/4 "2024-06-27T10:52:34Z")

</div>

Heads up for anyone that comes across the same challenge - Broberto’s suggestion worked

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [June 27, 2024, 10:53am UTC](https://community.weweb.io/t/assigning-user-roles-on-registration-2-roles-2-registration-forms-supabase-weweb/9330/5 "2024-06-27T10:53:44Z")

</div>

Which way did you end up picking? PG procedures or metadata?

---

<div class="post-metadata">

**Author:** ![waq.war](https://avatars.discourse-cdn.com/v4/letter/w/0ea827/32.png) [@waq.war](https://community.weweb.io/u/waq.war)\
**Post date:** [June 27, 2024, 11:51am UTC](https://community.weweb.io/t/assigning-user-roles-on-registration-2-roles-2-registration-forms-supabase-weweb/9330/6 "2024-06-27T11:51:30Z")

</div>

Metadata carrying a defined user\_role variable in weweb. Then a trigger/function in supabase to insert a new record into a Roles table when a new user is added to the auth.user table

---

<div class="post-metadata">

**Author:** ![romu](https://avatars.discourse-cdn.com/v4/letter/r/db5fbb/32.png) [@romu](https://community.weweb.io/u/romu)\
**Post date:** [January 22, 2025, 5:15pm UTC](https://community.weweb.io/t/assigning-user-roles-on-registration-2-roles-2-registration-forms-supabase-weweb/9330/7 "2025-01-22T17:15:12Z")

</div>

Hi @waq.war,  
Would you share the Supabase code to do this?

I tweaked a bit the function used to create the user profile in order to set the user role, but obviously it doesn’t work.

```auto
create function public.handle_new_user()
returns trigger
set search_path = ''
as $$
begin
  insert into public.user_profiles (id, email)
  values (new.id, new.email);
  insert into public.userRoles (userId, roleId)
  values (new.id, new.raw_user_meta_data->>'user_role');
  return new;
end;

```

Your code would be a great help.

Thanks.
