Fix register transaction typing for cross-site password update.

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