From 127e3b0e7a972f35bb09788fd1d25c61aa0b1f3b Mon Sep 17 00:00:00 2001 From: Sergio Ramirez Date: Mon, 15 Dec 2025 11:20:33 -0400 Subject: [PATCH] corregido erro codigo repetido auth --- apps/api/src/features/auth/auth.service.ts | 30 ++-------------------- package.json | 6 ++--- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/apps/api/src/features/auth/auth.service.ts b/apps/api/src/features/auth/auth.service.ts index 6a61aa4..2d09d9e 100644 --- a/apps/api/src/features/auth/auth.service.ts +++ b/apps/api/src/features/auth/auth.service.ts @@ -40,7 +40,7 @@ export class AuthService { private readonly config: ConfigService, @Inject(DRIZZLE_PROVIDER) private drizzle: NodePgDatabase, private readonly mailService: MailService, - ) { } + ) {} //Decode Tokens // Método para decodificar el token y obtener los datos completos @@ -294,18 +294,15 @@ export class AuthService { // console.log(session.length); - if (session.length === 0) throw new NotFoundException('session not found'); const user = await this.findUserById(user_id); if (!user) throw new NotFoundException('User not found'); - // Genera token const tokens = await this.generateTokens(user); const decodeAccess = this.decodeToken(tokens.access_token); const decodeRefresh = this.decodeToken(tokens.refresh_token); - // Actualiza session await this.drizzle .update(sessions) @@ -348,33 +345,11 @@ export class AuthService { } } - // Hash the password - const hashedPassword = await bcrypt.hash(createUserDto.password, 10); - - // Start a transaction - return await this.drizzle.transaction(async (tx) => { - // Create the user - const [newUser] = await tx - .insert(users) - .values({ - username: createUserDto.username, - email: createUserDto.email, - password: hashedPassword, - fullname: createUserDto.fullname, - isActive: true, - state: createUserDto.state, - municipality: createUserDto.municipality, - parish: createUserDto.parish, - phone: createUserDto.phone, - isEmailVerified: false, - isTwoFactorEnabled: false, - }) - .returning(); - // Hash the password const hashedPassword = await bcrypt.hash(createUserDto.password, 10); // Start a transaction return await this.drizzle.transaction(async (tx) => { + // Hash the password // Create the user const [newUser] = await tx .insert(users) @@ -396,7 +371,6 @@ export class AuthService { // check if user role is admin const role = createUserDto.role <= 2 ? 5 : createUserDto.role; // check if user role is admin - const role = createUserDto.role <= 2 ? 5 : createUserDto.role; // Assign role to user await tx.insert(usersRole).values({ diff --git a/package.json b/package.json index 8a7c788..09948e3 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,8 @@ "add:api": "pnpm add --filter=api", "add:web": "pnpm add --filter=web", "build": "turbo build", + "build:api": "pnpm build --filter=api", + "build:web": "pnpm build --filter=web", "changeset": "changeset", "clear:modules": "npx npkill", "commit": "cz", @@ -18,9 +20,7 @@ "lint": "turbo lint", "prepare": "husky", "start": "turbo start", - "test": "turbo test", - "build:api": "pnpm build --filter=api", - "build:web": "pnpm build --filter=web" + "test": "turbo test" }, "config": { "commitizen": {