fix admin middleware in server.ts
This commit is contained in:
parent
a94d3b5e05
commit
c9c1784dd7
@ -12,7 +12,7 @@ import cronJobs from "~/cron-jobs";
|
|||||||
import queues from "~/queues";
|
import queues from "~/queues";
|
||||||
import logger from "~/utils/logger.server";
|
import logger from "~/utils/logger.server";
|
||||||
import { __getSession } from "~/utils/session.server";
|
import { __getSession } from "~/utils/session.server";
|
||||||
import { type SessionUser } from "~/utils/auth.server";
|
import { type SessionData } from "~/utils/auth.server";
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
@ -76,8 +76,8 @@ app.listen(port, () => {
|
|||||||
|
|
||||||
async function adminMiddleware(req: Request, res: Response, next: NextFunction) {
|
async function adminMiddleware(req: Request, res: Response, next: NextFunction) {
|
||||||
const session = await __getSession(req.headers.cookie);
|
const session = await __getSession(req.headers.cookie);
|
||||||
const user: SessionUser | undefined = session.data.user;
|
const sessionData: SessionData | undefined = session.data.user;
|
||||||
if (!user || user.role !== GlobalRole.SUPERADMIN) {
|
if (!sessionData || sessionData.user.role !== GlobalRole.SUPERADMIN) {
|
||||||
return res.setHeader("Location", "/sign-in").status(302).end();
|
return res.setHeader("Location", "/sign-in").status(302).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user