From 9d56ec7396b8b9f4893ec2fb0af63c0baaaa3f9d Mon Sep 17 00:00:00 2001 From: Alireza Hassani Date: Fri, 21 Aug 2026 12:09:52 +0330 Subject: [PATCH] Fix register transaction typing for cross-site password update. Co-authored-by: Cursor --- src/auth/auth.service.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 24a2f78..5977a23 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -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 {