diff --git a/packages/core/src/database/find-many.test.ts b/packages/core/src/database/find-many.test.ts index b5ff16595..c1ec12975 100644 --- a/packages/core/src/database/find-many.test.ts +++ b/packages/core/src/database/find-many.test.ts @@ -7,7 +7,7 @@ import { buildFindMany } from './find-many'; describe('buildFindMany()', () => { it('matches expected sql', async () => { const pool = createTestPool( - 'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "role_names", "identities"\nfrom "users"' + 'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities"\nfrom "users"' ); const findMany = buildFindMany(pool, Users); await findMany(); @@ -15,7 +15,7 @@ describe('buildFindMany()', () => { it('matches expected sql with where conditions', async () => { const pool = createTestPool( - 'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "role_names", "identities"\nfrom "users"\nwhere "id"=$1' + 'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities"\nfrom "users"\nwhere "id"=$1' ); const findMany = buildFindMany(pool, Users); await findMany({ where: { id: '123' } }); @@ -23,7 +23,7 @@ describe('buildFindMany()', () => { it('matches expected sql with limit', async () => { const pool = createTestPool( - 'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "role_names", "identities"\nfrom "users"\nlimit $1' + 'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities"\nfrom "users"\nlimit $1' ); const findMany = buildFindMany(pool, Users); await findMany({ limit: 10 }); @@ -31,7 +31,7 @@ describe('buildFindMany()', () => { it('matches expected sql with offset', async () => { const pool = createTestPool( - 'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "role_names", "identities"\nfrom "users"\noffset $1' + 'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities"\nfrom "users"\noffset $1' ); const findMany = buildFindMany(pool, Users); await findMany({ offset: 10 }); @@ -39,7 +39,7 @@ describe('buildFindMany()', () => { it('matches expected sql with offset 0', async () => { const pool = createTestPool( - 'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "role_names", "identities"\nfrom "users"' + 'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities"\nfrom "users"' ); const findMany = buildFindMany(pool, Users); await findMany({ offset: 0 }); @@ -47,7 +47,7 @@ describe('buildFindMany()', () => { it('matches expected sql with where conditions, limit and offset', async () => { const pool = createTestPool( - 'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "role_names", "identities"\nfrom "users"\nwhere "id"=$1\nlimit $2\noffset $3' + 'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities"\nfrom "users"\nwhere "id"=$1\nlimit $2\noffset $3' ); const findMany = buildFindMany(pool, Users); await findMany({ where: { id: '123' }, limit: 20, offset: 20 }); diff --git a/packages/core/src/lib/register.ts b/packages/core/src/lib/register.ts index d8554c93f..7948c3fc2 100644 --- a/packages/core/src/lib/register.ts +++ b/packages/core/src/lib/register.ts @@ -170,6 +170,8 @@ export const registerWithSocial = async ( const id = await generateUserId(); await insertUser({ id, + name: userInfo.name ?? null, + avatar: userInfo.avatar ?? null, identities: { [connectorId]: { userId: userInfo.id, diff --git a/packages/schemas/src/db-entries/user.ts b/packages/schemas/src/db-entries/user.ts index bbd48ef7f..332eb70b4 100644 --- a/packages/schemas/src/db-entries/user.ts +++ b/packages/schemas/src/db-entries/user.ts @@ -20,6 +20,8 @@ export type CreateUser = { passwordEncrypted?: string | null; passwordEncryptionMethod?: PasswordEncryptionMethod | null; passwordEncryptionSalt?: string | null; + name?: string | null; + avatar?: string | null; roleNames?: RoleNames; identities?: Identities; }; @@ -32,6 +34,8 @@ export type User = { passwordEncrypted: string | null; passwordEncryptionMethod: PasswordEncryptionMethod | null; passwordEncryptionSalt: string | null; + name: string | null; + avatar: string | null; roleNames: RoleNames; identities: Identities; }; @@ -44,6 +48,8 @@ const createGuard: Guard = z.object({ passwordEncrypted: z.string().nullable().optional(), passwordEncryptionMethod: z.nativeEnum(PasswordEncryptionMethod).nullable().optional(), passwordEncryptionSalt: z.string().nullable().optional(), + name: z.string().nullable().optional(), + avatar: z.string().nullable().optional(), roleNames: roleNamesGuard.optional(), identities: identitiesGuard.optional(), }); @@ -59,6 +65,8 @@ export const Users: GeneratedSchema = Object.freeze({ passwordEncrypted: 'password_encrypted', passwordEncryptionMethod: 'password_encryption_method', passwordEncryptionSalt: 'password_encryption_salt', + name: 'name', + avatar: 'avatar', roleNames: 'role_names', identities: 'identities', }, @@ -70,6 +78,8 @@ export const Users: GeneratedSchema = Object.freeze({ 'passwordEncrypted', 'passwordEncryptionMethod', 'passwordEncryptionSalt', + 'name', + 'avatar', 'roleNames', 'identities', ], diff --git a/packages/schemas/tables/users.sql b/packages/schemas/tables/users.sql index 67116429f..985d59c87 100644 --- a/packages/schemas/tables/users.sql +++ b/packages/schemas/tables/users.sql @@ -8,6 +8,8 @@ create table users ( password_encrypted varchar(128), password_encryption_method password_encryption_method, password_encryption_salt varchar(128), + name varchar(128), + avatar varchar(256), role_names jsonb /* @use RoleNames */ not null default '[]'::jsonb, identities jsonb /* @use Identities */ not null default '{}'::jsonb, primary key (id)