0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

feat: set profiles from social connector (#226)

This commit is contained in:
Wang Sijie 2022-02-14 16:03:13 +08:00 committed by GitHub
parent cdcadb968f
commit e8c2b100a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 6 deletions

View file

@ -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 });

View file

@ -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,

View file

@ -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<CreateUser> = 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<CreateUser> = 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<CreateUser> = Object.freeze({
'passwordEncrypted',
'passwordEncryptionMethod',
'passwordEncryptionSalt',
'name',
'avatar',
'roleNames',
'identities',
],

View file

@ -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)