next.jsinternationalizationmiddlewarenext-authnextjs14

I can't get middleware stacking to work on next14 app router (for i18 and auth)


I'm working on a next14 project, I currently have middleware set for i18 and am trying to add a second middleware for authentication using auth.js (next-auth).

I've now gotten both middleware to work (i think?) but it looks like props are missing from my locale middleware.

Here's a github gist with all my code related to middlewares, including the file's location and any errors that are present in any file: code

in the screenshots below you can find the errors that nextjs is throwing. error message call stack

in localeMiddleware.ts, when logging, I get the following results:

The locale middleware by itself worked, with no errors, so I don't think there's anything wrong with my code there, but I guess I could be wrong...

Should I be passing props to the individual middleware files somehow? Also, is there any way I can check that the middleware work as expected?


Solution

  • Pulling a conversation from Discord into SO.... Having a single middleware is probably the best solution with some

     
    export function middleware(request: NextRequest) {
      if (request.nextUrl.pathname.startsWith('/about')) {
        // This logic is only applied to /about
      }
     
      if (request.nextUrl.pathname.startsWith('/dashboard')) {
        // This logic is only applied to /dashboard
      }
    }