Implementacion modulo de Fuel-Types

This commit is contained in:
2026-06-03 22:57:53 +00:00
parent d9584c2861
commit 7741bf06c5
8 changed files with 231 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import bcrypt from "bcrypt";
import jwt from "jsonwebtoken";
import userModel from "../user/user.model";
import { resolve } from "dns/promises";
export class AuthService {
@ -11,8 +12,9 @@ export class AuthService {
const user =
await userModel.findOne({
userName
});
}).populate("roleId");
//Validador de usuario existente
if (!user) {
throw new Error("Usuario no encontrado");
}
@ -30,11 +32,15 @@ export class AuthService {
user.lastLogin = new Date();
await user.save();
const role = user.roleId as any;
const token = jwt.sign(
{
id:user._id,
roleId: user.roleId
roleId: user.roleId,
roleName:role.roleName
},
process.env.JWT_SECRET as string,
@ -45,7 +51,19 @@ export class AuthService {
return {
token,
user
user:{
id: user._id,
employeeId:user.employeeId,
userName:user.userName,
roleId: role._id,
rolename: role.roleName,
active: user.active
}
};
}
}