OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
fix(seed): the seeded login can sign in again (#617)
ayushjhanwar-png3a017501f5b3
diff --git a/packages/seed/src/postgres.ts b/packages/seed/src/postgres.tsindex 16f91a3d8..9e0cb1727 100644--- a/packages/seed/src/postgres.ts+++ b/packages/seed/src/postgres.ts@@ -20,6 +20,8 @@ import {const MS_PER_YEAR = 365 * 86_400_000;const SECRET_HEX_CHARS = 20;+/** The provider email sign-in looks the account up by; copied from core's auth service. */+const CREDENTIAL_PROVIDER = 'credential';/** Sign-in accepts `$argon2` hashes made with these parameters; copied from core's auth `hashPassword`. */const ARGON2_OPTIONS = {memoryCost: 19_456,@@ -71,13 +73,19 @@ async function upsertUser(): Promise<string> {});const password = await argon2Hash(SEED_USER.password, ARGON2_OPTIONS);const account = await db.account.findFirst({- where: { userId: user.id, provider: 'email' },+ where: { userId: user.id, provider: CREDENTIAL_PROVIDER },});if (account) {await db.account.update({ where: { id: account.id }, data: { password } });} else {await db.account.create({- data: { userId: user.id, provider: 'email', email: user.email, password },+ data: {+ userId: user.id,+ provider: CREDENTIAL_PROVIDER,+ accountId: user.id,+ email: user.email,+ password,+ },});}return user.id;diff --git a/packages/seed/src/seed.integration.test.ts b/packages/seed/src/seed.integration.test.tsindex 020547791..d04d9f21f 100644--- a/packages/seed/src/seed.integration.test.ts+++ b/packages/seed/src/seed.integration.test.ts@@ -85,7 +85,7 @@ describe('seed against real databases', () => {expect(user?.accounts.some((account) =>- account.provider === 'email' &&+ account.provider === 'credential' &&account.password?.startsWith('$argon2'))).toBe(true);