Next-Intl and Auth0 - Need some help to create middleware.ts #848
Unanswered
FabioDainese
asked this question in
Q&A
Replies: 1 comment
-
I stumbled upon this a year later trying to get Next 15, auth0 middleware, and next-intl middleware to play nice with each other. Code below worked for me, wondering what worked for you. import createMiddleware from "next-intl/middleware";
import { routing } from "./i18n/routing";
import { auth0 } from "./lib/auth0";
import { NextRequest } from "next/server";
export async function middleware(request: NextRequest) {
const auth0Response = await auth0.middleware(request);
if (auth0Response && request.nextUrl.pathname !== "/") {
return auth0Response;
}
return createMiddleware(routing)(request);
}
export const config = {
matcher: [
"/",
"/(zh|en|ar)/:path*",
"/((?!_next/image|_next/static|images|api|favicon.ico|_vercel|.*\\..*).*)",
],
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys 👋 In my NextJS v14 project I would like to use both Next-Intl and Auth0, but I’m not quite sure on how to configure the
middleware.ts
file, since both libraries use it.Basically, here’s the code that next-intl needs to export from the
middleware.ts
file:Meanwhile, here’s the code that auth0 needs to export from the
middleware.ts
file (doc):Any idea on how to properly combine the two packages?
Finally, here’s a sandbox link of a project with minimal setup in order to play around (N.B. if you fork/download it, keep in mind to also create the
.env.local
file following the.env.example
boilerplate file).Beta Was this translation helpful? Give feedback.
All reactions