Next.js Discord

Discord Forum

Middleware :path Not Working

Unanswered
Catla posted this in #help-forum
Open in Discord
CatlaOP
import NextAuth from "next-auth";
import authConfig from "./auth.config";

const { auth } = NextAuth(authConfig);

export default auth((req) => {
    const { nextUrl } = req;
    const callbackUrl = nextUrl.pathname;
    const isLoggedIn = req.auth;

    if (!isLoggedIn) {
        return Response.redirect(new URL(`/api/signIn?callbackUrl=${callbackUrl}`, nextUrl));
    };

    return;
});

export const config = {
    matcher: ['/manage/guilds', '/manage/guilds/:path', '/manage/accounts'],
};


Hi.

My matchers for /manage/guilds and /manage/accounts work great. When the user is not signed in, indeed they are redirected to /api/signIn.

However, if a user is not logged in when accessing /manage/guilds/1092484 for example, the Middleware does not invoke.

Why, how do I fix this? Thanks.

1 Reply

CatlaOP
Bump