bcrypt utils

This commit is contained in:
Oliver Bryan
2025-12-22 03:23:05 +00:00
parent 22d05d8c26
commit 058387493e

View File

@@ -1,3 +1,4 @@
import bcrypt from "bcrypt";
import * as jwt from "jsonwebtoken";
const JWT_EXPIRES_IN = (process.env.JWT_EXPIRES_IN ?? "7d") as jwt.SignOptions["expiresIn"];
@@ -10,6 +11,10 @@ const requireJwtSecret = () => {
return secret;
};
export const hashPassword = (password: string) => bcrypt.hash(password, 10);
export const verifyPassword = (password: string, hash: string) => bcrypt.compare(password, hash);
export const generateToken = (userId: number) => {
const secret = requireJwtSecret();
return jwt.sign({ userId }, secret, { expiresIn: JWT_EXPIRES_IN });