aceptado cambios auth

This commit is contained in:
2025-12-15 10:53:36 -04:00
32 changed files with 5522 additions and 113 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,15 +294,18 @@ 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)
@@ -367,7 +370,31 @@ export class AuthService {
isTwoFactorEnabled: false,
})
.returning();
// 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();
// 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;