initial commit

This commit is contained in:
Alex Holliday committed 2025-11-13 13:47:26 -08:00
1 parent 7cb985116e
commit 75acf7b38f
955 files changed
+37333 -87054

No files matched your search

+29 -16
View File
@@ -1,22 +1,35 @@
import jwt from "jsonwebtoken";
import { AuthResult } from "../service/v2/business/AuthService.js";
import { AuthResult } from "@/services/business/AuthService.js";
import { IUserContext } from "@/db/models/index.js";
import bcrypt from "bcryptjs";
const encode = (data: AuthResult): string => {
const secret = process.env.JWT_SECRET;
if (!secret) {
throw new Error("JWT_SECRET is not defined");
}
const token = jwt.sign(data, secret, { expiresIn: "99d" });
return token;
export const encode = (data: AuthResult): string => {
const secret = process.env.JWT_SECRET;
if (!secret) {
throw new Error("JWT_SECRET is not defined");
}
const token = jwt.sign(data, secret, { expiresIn: "99d" });
return token;
};
const decode = (token: string): AuthResult => {
const secret = process.env.JWT_SECRET;
if (!secret) {
throw new Error("JWT_SECRET is not defined");
}
const decoded = jwt.verify(token, secret) as AuthResult;
return decoded;
export const decode = (token: string): IUserContext => {
const secret = process.env.JWT_SECRET;
if (!secret) {
throw new Error("JWT_SECRET is not defined");
}
const decoded = jwt.verify(token, secret) as IUserContext;
return decoded;
};
export { encode, decode };
export const hashPassword = async (password: string): Promise<string> => {
const saltRounds = 10;
const hash = await bcrypt.hash(password, saltRounds);
return hash;
};
export const compareHash = async (
password: string,
hash: string
): Promise<boolean> => {
return await bcrypt.compare(password, hash);
};