Issue #946

For security purposes, the auth schema is not exposed on the auto-generated API. We can make a profiles table in public namespace and mirror data from auth.users when user signs up.

I need id, username and raw_user_metadata so I will mirror these columns. For easy, you can leverage Supabase SQL Editor -> Quickstarts -> User Management Starter script

I don’t need Row Level Security as I manage database from server.

-- Create a table for public profiles
create table profiles (
  id uuid references auth.users on delete cascade not null primary key,
  username text,
  raw_app_meta_data jsonb

Let’s create a trigger function to add new row to profiles after row insert in auth.users

create function public.handle_new_user()
returns trigger as $$
  insert into public.profiles (id, username, raw_user_meta_data)
  values (, new.raw_user_meta_data->>'user_name', new.raw_user_meta_data);
  return new;
$$ language plpgsql security definer;
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();

The raw_user_meta_data is of type jsonb and it should look like below

  "avatar_url" : "",
  "email" : "",
  "email_verified" : true,
  "full_name" : "Khoa 🔥",
  "iss" : "",
  "name" : "Khoa 🔥",
  "picture" : "",
  "preferred_username" : "onmyway133",
  "provider_id" : "56019754",
  "sub" : "56019754",
  "user_name" : "onmyway133"

If you get 403, you need to check in Project settings -> Auth -> User Signups to ensure new users can sign up If you don’t see new rows in profiles, make sure you sign up with new user or delete old user records in auth.users, since the trigger happens on insert only

Read more