The user management example requires a specific database schema to handle user profiles and avatar storage via Row Level Security (RLS).
Profiles Table
Creates a profiles table linked to Supabase Auth. It includes policies allowing anyone to view profiles, but only the owner to insert or update their own profile.
Storage Buckets
Creates an avatars bucket in Supabase Storage with policies allowing public read access and allowing any user to upload images to that specific bucket.
Run the following SQL in your Supabase SQL Editor to set up the required schema:
-- Create a table for public "profiles"
create table profiles (
id uuid primary key,
user_id uuid not null,
username text,
website text,
avatar_url text,
inserted_at timestamp with time zone default timezone('utc'::text, now()) not null,
updated_at timestamp with time zone default timezone('utc'::text, now()) not null
);
alter table profiles enable row level security;
create policy "Public profiles are viewable by everyone."
on profiles for select
using ( true );
create policy "Users can insert their own profile."
on profiles for insert
with check ( auth.uid() = user_id );
create policy "Users can update own profile."
on profiles for update
using ( auth.uid() = user_id );
-- Set up Storage
insert into storage.buckets (id, name)
values ('avatars', 'avatars');
create policy "Avatar images are publicly accessible."
on storage.objects for select
using ( bucket_id = 'avatars' );
create policy "Anyone can upload an avatar."
on storage.objects for insert
with check ( bucket_id = 'avatars' );