Skip to content

Programmatically create new users #5043

Answered by jziggas
theo-m asked this question in Questions
Jan 18, 2022 · 16 comments · 21 replies
Discussion options

You must be logged in to vote

Fine, I'll do it myself. With blackjack and hookers.

CREATE OR REPLACE FUNCTION public.create_user(
    email text,
    password text
) RETURNS void AS $$
  declare
  user_id uuid;
  encrypted_pw text;
BEGIN
  user_id := gen_random_uuid();
  encrypted_pw := crypt(password, gen_salt('bf'));
  
  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)
  VALUES
    ('00000000-0000-0000-0000-000000000000', user_id, 'authenticated', 'authenticated', email, encrypted_pw, '2023-05…

Replies: 16 comments 21 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@Donnerstagnacht
Comment options

@MrAxle
Comment options

@Donnerstagnacht
Comment options

@Donnerstagnacht
Comment options

@elyseholladay
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@chuckcg
Comment options

Comment options

You must be logged in to vote
11 replies
@benrbowers
Comment options

@jziggas
Comment options

@benrbowers
Comment options

@jziggas
Comment options

Answer selected by awalias
@jacktho
Comment options

@Antiokh
Comment options

@alodevloper
Comment options

@barrownicholas
Comment options

Comment options

You must be logged in to vote
1 reply
@jziggas
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@Baxulio
Comment options

@Antiokh
Comment options

Comment options

You must be logged in to vote
1 reply
@tkrunning
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth All thing Supabase Auth related