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

@@ -40,7 +40,7 @@ export class AuthService {
private readonly config: ConfigService<Env>,
@Inject(DRIZZLE_PROVIDER) private drizzle: NodePgDatabase<typeof schema>,
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({

View File

@@ -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": {