KindeK
Kinde4mo ago
3 replies
0x7F

Next.js 15 + Kinde Auth – Protected routes not working after logout

Hey, I’m new to Next.js and I’m having the following issue:

I integrated Kinde login into my app, and login itself works fine. Afterwards, I want my routes to be protected – meaning that after logout I shouldn’t be able to access my pages/routes anymore unless I’m logged in.

The problem:
Even after logging out, I can still access my other pages – which should not be possible.

I followed a tutorial where the solution was to create a middleware.js in the lib folder with the following code:

import { withAuth } from '@kinde-oss/kinde-auth-nextjs/middleware';
import { NextRequest } from 'next/server';

export default function middleware(req: NextRequest) {
  return withAuth(req, {
    isReturnToCurrentPage: true,
  });
}

export const config = {
  matcher: [
    '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
  ],
};
Was this page helpful?