Next.js Discord

Discord Forum

next.config redirects for all paths except /login when cookie is missing

Unanswered
German yellowjacket posted this in #help-forum
Open in Discord
German yellowjacketOP
As the title says, I'm trying to setup a redirect for all paths except the /login path when a specific cookie is missing.

I can't get it to work but I don't see anything wrong in the config.

Is the config wrong or am I missunderstanding some concept?

async redirects() {
        return [
            {
                source: "/:path(^(?!.*login).*/?$)",
                missing: [
                    {
                        type: "cookie",
                        key: "_Host-sesh",
                    },
                ],
                destination: "/login",
                permanent: false,
            },
        ];
    },

5 Replies

German yellowjacketOP
When I say it doesn't work I mean when visiting "/" without the cookie, I'm not redirected.
German yellowjacketOP
Any help much appreciated!
hi @German yellowjacket
did you manage to solve your problem?
@Henrique Martins hi <@525765413322227742>
German yellowjacketOP
Hey Henrique. No I did not and I've abandoned Next since then