Fix register transaction typing for cross-site password update.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
e027cc96ea
commit
9d56ec7396
+15
-11
@@ -99,17 +99,19 @@ export class AuthService {
|
||||
|
||||
const linkedExistingAccount = Boolean(existingUser);
|
||||
|
||||
const user = await this.prisma.$transaction(async (tx) => {
|
||||
let account = existingUser;
|
||||
const userId = await this.prisma.$transaction(async (tx) => {
|
||||
let userId: bigint;
|
||||
|
||||
if (account) {
|
||||
if (existingUser) {
|
||||
// Cross-site join: replace Meshkee password with the one entered on this signup.
|
||||
account = await tx.user.update({
|
||||
where: { id: account.id },
|
||||
const updated = await tx.user.update({
|
||||
where: { id: existingUser.id },
|
||||
data: { passwordHash },
|
||||
select: { id: true },
|
||||
});
|
||||
userId = updated.id;
|
||||
} else {
|
||||
account = await tx.user.create({
|
||||
const created = await tx.user.create({
|
||||
data: {
|
||||
cellNumber: dto.cellNumber,
|
||||
passwordHash,
|
||||
@@ -118,20 +120,22 @@ export class AuthService {
|
||||
lastName: dto.lastName,
|
||||
cellVerifiedAt: smsEnabled ? null : new Date(),
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
userId = created.id;
|
||||
}
|
||||
|
||||
await tx.businessCustomer.create({
|
||||
data: {
|
||||
businessId: business.id,
|
||||
userId: account.id,
|
||||
userId,
|
||||
},
|
||||
});
|
||||
|
||||
const hasCustomerRole = await tx.userRole.findUnique({
|
||||
where: {
|
||||
userId_roleId: {
|
||||
userId: account.id,
|
||||
userId,
|
||||
roleId: customerRole.id,
|
||||
},
|
||||
},
|
||||
@@ -140,16 +144,16 @@ export class AuthService {
|
||||
if (!hasCustomerRole) {
|
||||
await tx.userRole.create({
|
||||
data: {
|
||||
userId: account.id,
|
||||
userId,
|
||||
roleId: customerRole.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return account;
|
||||
return userId;
|
||||
});
|
||||
|
||||
const authUser = await this.getAuthUser(user.id);
|
||||
const authUser = await this.getAuthUser(userId);
|
||||
const tokens = await this.issueTokens(authUser);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user