Skip to content

How to redirect users when accessing GraphQL playground #7487

Answered by jcubic
jcubic asked this question in Q&A
Discussion options

You must be logged in to vote

Ok found that app.use() accepts any number of middlewares, so I can use add my is_admin middleware to the list:

import { Request, Response, NextFunction } from 'express';

export function is_admin(req: Request, res: Response, next: NextFunction) {
    if (!req.session.admin && !DEBUG) {
        return res.redirect(302, `${ADMIN_LOGIN}?next=${next_url(req)}`);
    }
    next();
}

export const start = async (port: number, callback: () => void) => {
    const httpServer = http.createServer(app);
    const server = apollo_server(httpServer);
    await server.start();
    app.use(
        '/api/',
        cors<cors.CorsRequest>({ origin: "*" }),
        json(),
        is_admin,
        expre…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jcubic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant