fix(auth+bugs): optional auth bypass, login routes, conform column name, panel metadata fields, login page: auth.js

This commit is contained in:
Zac Gaetano 2026-05-15 23:40:10 -04:00
parent 583b3f0ad6
commit 069c20ad43

View file

@ -1,4 +1,16 @@
/**
* Authentication middleware.
*
* When AUTH_ENABLED=true in the environment, every protected route requires
* an active session (set by POST /api/v1/auth/login).
*
* When AUTH_ENABLED is unset or any other value, the middleware is a no-op
* so the stack can be deployed and tested without setting up users first.
* Set AUTH_ENABLED=true in production after running POST /api/v1/auth/setup
* to create the first admin account.
*/
export const requireAuth = (req, res, next) => {
if (process.env.AUTH_ENABLED !== 'true') return next();
if (!req.session || !req.session.userId) {
return res.status(401).json({ error: 'Unauthorized' });
}