fix admin middleware in server.ts

This commit is contained in:
m5r 2022-05-24 21:31:39 +02:00
parent a94d3b5e05
commit c9c1784dd7

View File

@ -12,7 +12,7 @@ import cronJobs from "~/cron-jobs";
import queues from "~/queues";
import logger from "~/utils/logger.server";
import { __getSession } from "~/utils/session.server";
import { type SessionUser } from "~/utils/auth.server";
import { type SessionData } from "~/utils/auth.server";
const app = express();
app.use((req, res, next) => {
@ -76,8 +76,8 @@ app.listen(port, () => {
async function adminMiddleware(req: Request, res: Response, next: NextFunction) {
const session = await __getSession(req.headers.cookie);
const user: SessionUser | undefined = session.data.user;
if (!user || user.role !== GlobalRole.SUPERADMIN) {
const sessionData: SessionData | undefined = session.data.user;
if (!sessionData || sessionData.user.role !== GlobalRole.SUPERADMIN) {
return res.setHeader("Location", "/sign-in").status(302).end();
}