© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•13mo ago•
6 replies
JH

Auth Admin CreateUser() and SQL function

i've created a component on my app so a admin can create a user (normal sign-ups are disabled)

    const supabase = await createAdminClient();
    const { data, error } = await supabase.auth.admin.createUser({
      email: email,
      password: password,
      app_metadata: { org_id: {org_uuid}, role: role },
    });
    const supabase = await createAdminClient();
    const { data, error } = await supabase.auth.admin.createUser({
      email: email,
      password: password,
      app_metadata: { org_id: {org_uuid}, role: role },
    });

ive also got a trigger which runs a function AFTER the data is input into the auth.users

function:
  BEGIN
    INSERT INTO public.users(id, avatar, org_id)
    VALUES (
      NEW.id,
      'https://....supabase.co/storage...' || (FLOOR(RANDOM() * 42) + 1)::TEXT || '.jpg',
      (NEW.raw_app_meta_data->>'org_id')::uuid
    );
    RETURN NEW;
END;
  BEGIN
    INSERT INTO public.users(id, avatar, org_id)
    VALUES (
      NEW.id,
      'https://....supabase.co/storage...' || (FLOOR(RANDOM() * 42) + 1)::TEXT || '.jpg',
      (NEW.raw_app_meta_data->>'org_id')::uuid
    );
    RETURN NEW;
END;

this runs fine other than the org_id being picked up and added into the public.users table, it just displays as an empty NULL

in my public.users the org_id(UUID type) is a fkey to my organisations table
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Create user with supabase.auth.admin.createUser without password
SupabaseSSupabase / help-and-questions
3y ago
auth.sign_in_with_password SQL function
SupabaseSSupabase / help-and-questions
4mo ago
auth.admin.createUser() returns 'permission denied for schema vault' on self host env
SupabaseSSupabase / help-and-questions
9mo ago
Updated SQL function
SupabaseSSupabase / help-and-questions
4y ago