Next.js Discord

Discord Forum

Middleware not working

Unanswered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
I have a simple middleware inside my middleware.ts that works like this
export default async function middleware(request: NextRequest) {
    const sessionString = request.cookies.get('session')?.value

    if (!sessionString) {
        return NextResponse.redirect(new URL("/login", request.url));
    }


    const parsedData: SessionData = JSON.parse(sessionString);
    await extendSession(parsedData);

    return NextResponse.next();
}

export const config = {
    matcher: '/((?!login).*)', //Match every route except for /login
}

But I don't know why, as you can see from the screen it's messing with my login page. Those 15 error are coming from just 1 page load.

Any clue?

0 Replies