revert feat(auth): bearer token desteği ve çoklu origin ayarı ekle - Authorization header ile Bearer token kimlik doğrulaması eklendi - Token'ların localStorage'da saklanması desteği eklendi - WEB_ALLOWED_ORIGINS ve WEB_ALLOWED_HOSTS konfigürasyonları eklendi - Loop işlerinde profileId ve profileName alanları eklendi - CORS ve Vite sunucusu için çoklu origin desteği sağlandı
23 lines
600 B
TypeScript
23 lines
600 B
TypeScript
import { Request, Response, NextFunction } from "express";
|
|
import { verifyToken } from "./auth.service"
|
|
|
|
export const requireAuth = (req: Request, res: Response, next: NextFunction) => {
|
|
const token = req.cookies?.["qbuffer_token"];
|
|
if (!token) {
|
|
return res.status(401).json({ error: "Unauthorized" });
|
|
}
|
|
try {
|
|
const payload = verifyToken(token);
|
|
req.user = payload;
|
|
return next();
|
|
} catch (error) {
|
|
return res.status(401).json({ error: "Unauthorized" });
|
|
}
|
|
};
|
|
|
|
declare module "express-serve-static-core" {
|
|
interface Request {
|
|
user?: { username: string };
|
|
}
|
|
}
|