mirror of
https://github.com/hex248/sprint.git
synced 2026-02-07 18:23:03 +00:00
bcrypt utils
This commit is contained in:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user