feat: basic api setup and boilerplate
This commit is contained in:
12
backend/src/utils/jwt.js
Normal file
12
backend/src/utils/jwt.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import jwt from "jsonwebtoken";
|
||||
import "dotenv/config";
|
||||
|
||||
const SECRET = process.env.JWT_SECRET;
|
||||
|
||||
export function generateToken(payload) {
|
||||
return jwt.sign(payload, SECRET, {expiresIn: "24h"});
|
||||
}
|
||||
|
||||
export function verifyToken(token) {
|
||||
return jwt.verify(token, SECRET);
|
||||
}
|
||||
9
backend/src/utils/password.js
Normal file
9
backend/src/utils/password.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import bcrypt from "bcryptjs";
|
||||
|
||||
export async function hashPassword(password) {
|
||||
return bcrypt.hash(password, 10);
|
||||
}
|
||||
|
||||
export async function comparePassword(password, hash) {
|
||||
return bcrypt.compare(password, hash);
|
||||
}
|
||||
Reference in New Issue
Block a user