Can't seed or signup auth users locally #9251
|
I'm trying to get my local Supabase dev environment working, and I'm stuck getting Supabase auth working in local dev. I've tried seeding a dummy user in insert into auth.users (instance_id, id, aud, role, email, encrypted_password, raw_app_meta_data, raw_user_meta_data, email_confirmed_at, created_at)
values ('00000000-0000-0000-0000-000000000000', '185f2f83-d63a-4c9b-b4a0-7e4a885799e2', 'authenticated', 'authenticated', 'madi@bokeh.photo', '$2a$10$6gPtvpqCAiwavx1EOnjIgOykKMgzRdiBuejUQGIRRjvUi/ZgMh.9C', '{"provider":"email","providers":["email"]}', '{}', timezone('utc'::text, now()), timezone('utc'::text, now()));
insert into auth.identities (id, user_id, identity_data, provider, created_at)
values ('185f2f83-d63a-4c9b-b4a0-7e4a885799e2', '185f2f83-d63a-4c9b-b4a0-7e4a885799e2', '{"sub": "185f2f83-d63a-4c9b-b4a0-7e4a885799e2"}', 'email', timezone('utc'::text, now()));But when trying to login Supabase throws invalid login credentials errors (the encrypted password is taken from a pg_dump of a user I know the password to in my prod db) I also tried signing up when running a local DB, but Supabase throws a cryptic Any ideas? |
Replies: 9 comments 30 replies
|
Anyone? |
|
Found it! For anyone else coming across this, in my case it was accessing a function in an extension (eg: |
|
I'm getting the same errors on local. I can sign up for an account and that works... but the seed script user get a 500 server error. When I compare the created user and the seed script user, they are identical in the users table, identity table, and profiles table... Very odd. Here is my seed script if anyone is wondering: `-- Default User INSERT INTO |
|
you're welcome |
|
Wrote this python script to automatically generate a bunch of users, with correctly hashing different passwords (dropping below for anyone who stumbles across this thread). Install Dependenciespython3 -m venv venv
source ./venv/bin/activateThen in the venv: pip3 install --upgrade pip
pip3 install Faker
pip3 install bcrypt
ScriptRun the below script and then just copy the output into from uuid import uuid4 # built-in / std lib include
from faker import Faker
import bcrypt
fake = Faker()
class User:
def __init__(self):
self.id_ = str(uuid4())
self.email = fake.email()
self.password = fake.password()
self.hashed_password = self.hash_password(self.password)
@staticmethod
def hash_password(pwd: str):
bytes_ = pwd.encode('utf-8')
salt = bcrypt.gensalt(rounds=10, prefix=b"2a")
hash = bcrypt.hashpw(bytes_, salt)
return hash.decode()
def auth_user(self) -> str:
s = f"""('00000000-0000-0000-0000-000000000000', '{self.id_}', 'authenticated', 'authenticated', '{self.email}', '{self.hashed_password}', '2023-05-03 19:41:43.585805+00', NULL, '', NULL, '', '2023-04-22 13:10:03.275387+00', '', '', NULL, '2023-04-22 13:10:31.458239+00', '{{"provider":"email","providers":["email"]}}', '{{}}', NULL, '2023-05-03 19:41:43.580424+00', '2023-05-03 19:41:43.585948+00', NULL, NULL, '', '', NULL, '', 0, NULL, '', NULL)"""
return s
def auth_identity(self) -> str:
s = f"""('{self.id_}', '{self.id_}'::uuid, '{{"sub":"{self.id_}","email":"{self.email}"}}', 'email', '2023-05-03 19:41:43.582456+00', '2023-05-03 19:41:43.582497+00', '2023-05-03 19:41:43.582497+00')"""
return s
def __repr__(self):
return self.single_row()
if __name__ == "__main__":
users: list[User] = [User() for _ in range(15)]
print("""INSERT INTO auth.users (instance_id, id, aud, role, email, encrypted_password, email_confirmed_at, invited_at, confirmation_token, confirmation_sent_at, recovery_token, recovery_sent_at, email_change_token_new, email_change, email_change_sent_at, last_sign_in_at, raw_app_meta_data, raw_user_meta_data, is_super_admin, created_at, updated_at, phone, phone_confirmed_at, phone_change, phone_change_token, phone_change_sent_at, email_change_token_current, email_change_confirm_status, banned_until, reauthentication_token, reauthentication_sent_at)\n VALUES""")
for index, user in enumerate(users):
line_terminator = ("," if index is not (len(users)-1) else ";")
print(f" {user.auth_user()}{line_terminator}")
print("""INSERT INTO auth.identities (id,user_id,identity_data,provider,last_sign_in_at,created_at,updated_at)\n VALUES""")
for index, user in enumerate(users):
line_terminator = ("," if index is not (len(users) - 1) else ";")
print(f" {user.auth_identity()}{line_terminator}")Output from the above script will look like: |
|
I am also getting an error when trying to seed users locally. I am having an Here is my codesnippet: INSERT INTO auth.users (instance_id,id,aud,"role",email,encrypted_password,email_confirmed_at,last_sign_in_at,raw_app_meta_data,raw_user_meta_data,is_super_admin,created_at,updated_at,phone,phone_confirmed_at,confirmation_token,email_change,email_change_token_new,recovery_token) VALUES
('00000000-0000-0000-0000-000000000000'::uuid,'f76629c5-a070-4bbc-9918-64beaea48848'::uuid,'authenticated','authenticated','test@example.com','$2a$10$PznXR5VSgzjnAp7T/X7PCu6vtlgzdFt1zIr41IqP0CmVHQtShiXxS','2022-02-11 21:02:04.547','2022-02-11 22:53:12.520','{"provider": "email", "providers": ["email"]}','{}',FALSE,'2022-02-11 21:02:04.542','2022-02-11 21:02:04.542',NULL,NULL,'','','',''),
('00000000-0000-0000-0000-000000000000'::uuid,'d9064bb5-1501-4ec9-bfee-21ab74d645b8'::uuid,'authenticated','authenticated','demo@example.com','$2a$10$mOJUAphJbZR4CdM38.bgOeyySurPeFHoH/T1s7HuGdpRb7JgatF7K','2022-02-12 07:40:23.616','2022-02-12 07:40:23.621','{"provider": "email", "providers": ["email"]}','{}',FALSE,'2022-02-12 07:40:23.612','2022-02-12 07:40:23.613',NULL,NULL,'','','','')
ON CONFLICT (id) DO NOTHING;
INSERT INTO auth.identities (id,user_id,identity_data,provider,last_sign_in_at,created_at,updated_at) VALUES
('f76629c5-a070-4bbc-9918-64beaea48848','f76629c5-a070-4bbc-9918-64beaea48848'::uuid,'{"sub": "f76629c5-a070-4bbc-9918-64beaea48848"}','email','2022-02-11 21:02:04.545','2022-02-11 21:02:04.545','2022-02-11 21:02:04.545'),
('d9064bb5-1501-4ec9-bfee-21ab74d645b8','d9064bb5-1501-4ec9-bfee-21ab74d645b8'::uuid,'{"sub": "d9064bb5-1501-4ec9-bfee-21ab74d645b8"}','email','2022-02-12 07:40:23.615','2022-02-12 07:40:23.615','2022-02-12 07:40:23.615')
ON CONFLICT (id, provider) DO NOTHING;Can you please help me, why my seeding is failing? |
|
I posted this in another issue as well. Here is some code to seed users programmatically: Usage: Edit: I corrected a couple errors that can cause FK problems. Tested and working now. |
|
Found another solution:
|
|
for future reference if anyone want to know how to run |
Found it! For anyone else coming across this, in my case it was accessing a function in an extension (eg:
gen_random_uuidfrompgcrypto). In my live Supabase account that's in the search path so I can just call it normally, in my local dev environment it's not for whatever reason, so I have to callextensions.gen_random_uuid()explicitly.