cos tam dziala

This commit is contained in:
Patryk Koreń
2026-07-09 20:14:56 +02:00
parent ff707dd762
commit 65303e655b
18 changed files with 235 additions and 153 deletions

View File

@@ -2,30 +2,17 @@ import jwt from "jsonwebtoken";
import type { Request, Response, NextFunction } from "express";
export function authMiddleware(req: Request, res: Response, next: NextFunction) {
// const header = req.headers.authorization;
// const error = "You must be logged in to access this page"
// if (!header) {
// return res.status(401).json({ error });
// }
// const token = header.split(" ")[1]; // "Bearer TOKEN"
// try {
// if (!token) throw new Error("No Bearer Token")
// const decoded = jwt.verify(token, process.env.JWT_SECRET!);
// (req as any).user = decoded;
// next();
// } catch (err) {
// return res.status(401).json({ error });
// }
const token = req.cookies.token;
if (!token) return res.sendStatus(401);
try {
const decoded = jwt.verify(token, process.env.JWT_SECRET!) as jwt.JwtPayload;
req.user = decoded;
const token = req.cookies.token;
if (!token) { return res.sendStatus(401); }
console.log("Token: ", token)
console.log("Secret: ", process.env.JWT_SECRET)
jwt.verify(token, process.env.JWT_SECRET!)
next();
} catch {
res.sendStatus(403);
}