SupabaseS
Supabase12mo ago
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 },
    });

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;

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
Was this page helpful?