corregido erro codigo repetido auth

This commit is contained in:
2025-12-15 11:20:33 -04:00
parent ee499abcf9
commit 127e3b0e7a
2 changed files with 5 additions and 31 deletions

View File

@@ -294,18 +294,15 @@ export class AuthService {
// console.log(session.length); // console.log(session.length);
if (session.length === 0) throw new NotFoundException('session not found'); if (session.length === 0) throw new NotFoundException('session not found');
const user = await this.findUserById(user_id); const user = await this.findUserById(user_id);
if (!user) throw new NotFoundException('User not found'); if (!user) throw new NotFoundException('User not found');
// Genera token // Genera token
const tokens = await this.generateTokens(user); const tokens = await this.generateTokens(user);
const decodeAccess = this.decodeToken(tokens.access_token); const decodeAccess = this.decodeToken(tokens.access_token);
const decodeRefresh = this.decodeToken(tokens.refresh_token); const decodeRefresh = this.decodeToken(tokens.refresh_token);
// Actualiza session // Actualiza session
await this.drizzle await this.drizzle
.update(sessions) .update(sessions)
@@ -348,33 +345,11 @@ export class AuthService {
} }
} }
// Hash the password
const hashedPassword = await bcrypt.hash(createUserDto.password, 10); const hashedPassword = await bcrypt.hash(createUserDto.password, 10);
// Start a transaction // Start a transaction
return await this.drizzle.transaction(async (tx) => { 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 // Hash the password
const hashedPassword = await bcrypt.hash(createUserDto.password, 10);
// Start a transaction
return await this.drizzle.transaction(async (tx) => {
// Create the user // Create the user
const [newUser] = await tx const [newUser] = await tx
.insert(users) .insert(users)
@@ -396,7 +371,6 @@ export class AuthService {
// check if user role is admin // check if user role is admin
const role = createUserDto.role <= 2 ? 5 : createUserDto.role; const role = createUserDto.role <= 2 ? 5 : createUserDto.role;
// check if user role is admin // check if user role is admin
const role = createUserDto.role <= 2 ? 5 : createUserDto.role;
// Assign role to user // Assign role to user
await tx.insert(usersRole).values({ await tx.insert(usersRole).values({

View File

@@ -7,6 +7,8 @@
"add:api": "pnpm add --filter=api", "add:api": "pnpm add --filter=api",
"add:web": "pnpm add --filter=web", "add:web": "pnpm add --filter=web",
"build": "turbo build", "build": "turbo build",
"build:api": "pnpm build --filter=api",
"build:web": "pnpm build --filter=web",
"changeset": "changeset", "changeset": "changeset",
"clear:modules": "npx npkill", "clear:modules": "npx npkill",
"commit": "cz", "commit": "cz",
@@ -18,9 +20,7 @@
"lint": "turbo lint", "lint": "turbo lint",
"prepare": "husky", "prepare": "husky",
"start": "turbo start", "start": "turbo start",
"test": "turbo test", "test": "turbo test"
"build:api": "pnpm build --filter=api",
"build:web": "pnpm build --filter=web"
}, },
"config": { "config": {
"commitizen": { "commitizen": {