fix(auth): Fix admin user authentication for /users/db-health endpoin… #422

Merged
suraimu-team merged 1 commits from fix/admin-cookie-jwt into dev-1.8.0 2025-10-20 18:01:58 +00:00

View File

@@ -223,12 +223,19 @@ class AuthManager {
createAdminMiddleware() {
return async (req: Request, res: Response, next: NextFunction) => {
const authHeader = req.headers["authorization"];
if (!authHeader?.startsWith("Bearer ")) {
return res.status(401).json({ error: "Missing Authorization header" });
let token = req.cookies?.jwt;
if (!token) {
const authHeader = req.headers["authorization"];
if (authHeader?.startsWith("Bearer ")) {
token = authHeader.split(" ")[1];
}
}
if (!token) {
return res.status(401).json({ error: "Missing authentication token" });
}
const token = authHeader.split(" ")[1];
const payload = await this.verifyJWTToken(token);
if (!payload) {