Production creates the SuperAdmin from env credentials, and dashboard seeding is authenticated, SuperAdmin-only, and locked after the first run.
19 lines
371 B
JavaScript
19 lines
371 B
JavaScript
// /middlewares/requireSuperAdmin.js
|
|
'use strict';
|
|
|
|
const AppError = require('../utils/AppError');
|
|
|
|
const requireSuperAdmin = (req, res, next) => {
|
|
if (!req.user) {
|
|
return next(new AppError('UNAUTHORIZED'));
|
|
}
|
|
|
|
if (req.user.role?.name !== 'SuperAdmin') {
|
|
return next(new AppError('FORBIDDEN'));
|
|
}
|
|
|
|
return next();
|
|
};
|
|
|
|
module.exports = requireSuperAdmin;
|