first commit

This commit is contained in:
2026-05-23 14:14:50 +03:30
commit 2a22bab127
48 changed files with 7554 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
import createHttpError from "http-errors";
import { AuthMessages } from "../messages";
import jwt from "jsonwebtoken";
import dotenv from "dotenv";
import User from "../../../models/User";
import { JWT_SECRET } from "../../../core/constants";
dotenv.config();
class AuthServiceClass {
async login(username: string, password: string) {
try {
const user = await User.findOne({
where: {
nationalCode: username,
mobile: password,
},
});
if (!user) {
throw createHttpError.Unauthorized(
AuthMessages.error.login.incorrectData,
);
}
const token = jwt.sign(
{
id: user.id,
roleId: user.roleId,
},
JWT_SECRET,
{ expiresIn: "1d" },
);
return token;
} catch (error) {
console.log(error);
throw createHttpError.InternalServerError(
AuthMessages.error.login.loginFailed,
);
}
}
}
const AuthService = new AuthServiceClass();
export default AuthService;