- Created WatchBuddy model - M:N junctions to EntrySeen/EpisodeSeen and Media relation for profile pictures - Full CRUD + search + profile picture upload - WatchBuddySelect multi-select with search and inline create, replaced all seen_with text inputs - WatchBuddiesPage (grid) and WatchBuddyProfilePage (edit form, icon-based contacts, poster-grid watch history, monthly timeline)
31 lines
794 B
JavaScript
31 lines
794 B
JavaScript
const jwt = require("jsonwebtoken");
|
|
const configService = require("../services/configService");
|
|
|
|
function authMiddleware(req, res, next) {
|
|
// Skip auth for login/verify/media endpoints
|
|
if (
|
|
req.path === "/auth/login" ||
|
|
req.path === "/auth/verify" ||
|
|
req.path.startsWith("/media/")
|
|
) {
|
|
return next();
|
|
}
|
|
|
|
const auth = req.headers.authorization;
|
|
if (!auth || !auth.startsWith("Bearer ")) {
|
|
return res.status(401).json({ error: "Authentication required" });
|
|
}
|
|
|
|
const settings = configService.getSettings();
|
|
const jwtSecret = settings.jwtSecret || "showy-default-secret";
|
|
|
|
try {
|
|
jwt.verify(auth.slice(7), jwtSecret);
|
|
next();
|
|
} catch {
|
|
return res.status(401).json({ error: "Invalid or expired token" });
|
|
}
|
|
}
|
|
|
|
module.exports = authMiddleware;
|