Skip to content

Supabase: hash passwords when adding to auth.users table to enable logging in. #208

Open
@lockykeaney-convincely

Description

@lockykeaney-convincely

Feature request

Is your feature request related to a problem? Please describe.

When adding users to Supabase, the password is hashed on the database side as part of the createUser function. When seeding, that encryption can't be matched by bcrypt, resulting in an invalid password. Seeded users can't be used for manual testing.

Describe the solution you'd like

A way to access the postgres functions on the db instance, or ability to execute sql with the seed function:

const result = await seed.$db.query(`
       INSERT INTO auth.users (
            aud,
            email,
            encrypted_password,
            role,
            raw_app_meta_data
       ) VALUES (
            $1,
            $2,
            crypt($3, gen_salt('bf')),
            $4,
            $5
       ) RETURNING *
        `, [
          'Seed Test User',
          '[email protected]',
          'SeedTest1234',
          'authenticated',
          {
            provider: 'email',
            providers: ['email'],
            claims_admin: true,
          }
        ]);

    return result.rows;
});

or

await seed.users([
    {
      aud: 'Seed Test User',
      email:  '[email protected]',
      encrypted_password: seed.sql`crypt('SeedTest1234', gen_salt('bf'))`,
      role: 'authenticated',
      raw_app_meta_data: {
        provider: 'email',
        providers: ['email'],
        claims_admin: true,
      },
    },
  ]);

Describe alternatives you've considered

  • Passing an sql file to the defineConfig function with some default users created with raw sql and make them available to the seed context
  • Adding a migration to the db that checks if the password is encrypted, to try and mock the functionality of supabase directly on the db
  • Creating a supabase client in the seed function, and adding the return values to the seed ctx somehow

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions