Seeding Supabase Users
2024-04-09During a recent project, I needed to seed a local Supabase instance with a bunch of users. I hadn't done this before, but it turned out to be quite simple. Just update your seed.sql
file with the following:
-- Create 10 users
INSERT INTO
auth.users (
instance_id,
id,
aud,
role,
email,
encrypted_password,
email_confirmed_at,
recovery_sent_at,
last_sign_in_at,
raw_app_meta_data,
raw_user_meta_data,
created_at,
updated_at,
confirmation_token,
email_change,
email_change_token_new,
recovery_token
) (
SELECT
'00000000-0000-0000-0000-000000000000',
uuid_generate_v4 (),
'authenticated',
'authenticated',
'user' || (ROW_NUMBER() OVER ()) || '@example.com',
crypt ('password123', gen_salt ('bf')),
current_timestamp,
current_timestamp,
current_timestamp,
'{"provider":"email","providers":["email"]}',
'{}',
current_timestamp,
current_timestamp,
'',
'',
'',
''
FROM
generate_series(1, 10)
);
-- Create 10 identities, one for each user
INSERT INTO
auth.identities (
id,
user_id,
-- New column
provider_id,
identity_data,
provider,
last_sign_in_at,
created_at,
updated_at
) (
SELECT
uuid_generate_v4 (),
id,
-- New column
id,
format('{"sub":"%s","email":"%s"}', id :: text, email) :: jsonb,
'email',
current_timestamp,
current_timestamp,
current_timestamp
FROM
auth.users
);
This script will create 10 users with the email user<0-9>@example.com
and password password123
. You can adjust the number of users by changing the generate_series
argument.