fix(server): user can not signup through oauth if ever invited (#6101)

This commit is contained in:
liuyi
2024-03-13 07:50:10 +00:00
parent fd9084ea6a
commit 573528be41
9 changed files with 58 additions and 13 deletions

View File

@@ -42,7 +42,9 @@ export class UserManagementResolver {
if (user) {
return this.feature.addEarlyAccess(user.id);
} else {
const user = await this.users.createAnonymousUser(email);
const user = await this.users.createAnonymousUser(email, {
registered: false,
});
return this.feature.addEarlyAccess(user.id);
}
}

View File

@@ -11,11 +11,12 @@ export class UserService {
email: true,
emailVerifiedAt: true,
avatarUrl: true,
registered: true,
} satisfies Prisma.UserSelect;
constructor(private readonly prisma: PrismaClient) {}
get userCreatingData(): Partial<Prisma.UserCreateInput> {
get userCreatingData() {
return {
name: 'Unnamed',
features: {
@@ -106,6 +107,26 @@ export class UserService {
return this.createAnonymousUser(email, data);
}
async fulfillUser(
email: string,
data: Partial<
Pick<Prisma.UserCreateInput, 'emailVerifiedAt' | 'registered'>
>
) {
return this.prisma.user.upsert({
select: this.defaultUserSelect,
where: {
email,
},
update: data,
create: {
email,
...this.userCreatingData,
...data,
},
});
}
async deleteUser(id: string) {
return this.prisma.user.delete({ where: { id } });
}