mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 18:33:01 +00:00
bcrypt utils
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import bcrypt from "bcrypt";
|
||||||
import * as jwt from "jsonwebtoken";
|
import * as jwt from "jsonwebtoken";
|
||||||
|
|
||||||
const JWT_EXPIRES_IN = (process.env.JWT_EXPIRES_IN ?? "7d") as jwt.SignOptions["expiresIn"];
|
const JWT_EXPIRES_IN = (process.env.JWT_EXPIRES_IN ?? "7d") as jwt.SignOptions["expiresIn"];
|
||||||
@@ -10,6 +11,10 @@ const requireJwtSecret = () => {
|
|||||||
return secret;
|
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) => {
|
export const generateToken = (userId: number) => {
|
||||||
const secret = requireJwtSecret();
|
const secret = requireJwtSecret();
|
||||||
return jwt.sign({ userId }, secret, { expiresIn: JWT_EXPIRES_IN });
|
return jwt.sign({ userId }, secret, { expiresIn: JWT_EXPIRES_IN });
|
||||||
|
|||||||
Reference in New Issue
Block a user