feat: bootstrap SuperAdmin from env and lock one-time seeding
Production creates the SuperAdmin from env credentials, and dashboard seeding is authenticated, SuperAdmin-only, and locked after the first run.
This commit is contained in:
@@ -4,6 +4,7 @@ const jwt = require('jsonwebtoken');
|
||||
const config = require('../config/config');
|
||||
const AppError = require('../utils/AppError');
|
||||
const User = require('../components/users/userModel');
|
||||
const { isBootstrapSuperAdminDisabled } = require('../utils/superAdmin');
|
||||
|
||||
const authMiddleware = async (req, res, next) => {
|
||||
try {
|
||||
@@ -29,7 +30,7 @@ const authMiddleware = async (req, res, next) => {
|
||||
}
|
||||
|
||||
const user = await User.findById(decoded.id).populate('role');
|
||||
if (!user || !user.isActive) {
|
||||
if (!user || !user.isActive || isBootstrapSuperAdminDisabled(user)) {
|
||||
return next(new AppError('UNAUTHORIZED'));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user