+ signup and + verify
All checks were successful
gitea/MERN_STACK_TEMPLATE/pipeline/head This commit looks good

This commit is contained in:
2025-05-02 22:19:30 +02:00
parent 7333cf79bd
commit 3f76d4f3d4
12 changed files with 589 additions and 22 deletions

View File

@ -0,0 +1,16 @@
import jwt from "jsonwebtoken";
export const generateTokenAndSetCookie = (res, userId) => {
const token = jwt.sign({ userId}, process.env.JWT_SECRET, {
expiresIn: "7d",
});
res.cookie("token", token, {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
sameSite: "strict",
maxAge: 7 * 24 * 60 * 60 * 1000,
});
return token;
}