I have a next js application which has multiple lingual support. So I have a middleware to redirect users to URL with the locale. I want to implement auth js in this application.
export function middleware(request: any) {
const pathname = request.nextUrl.pathname;
const pathnameIsMissingLocale = locales.every(
(locale) => !pathname.startsWith(`/${locale}/`) && pathname !== `/${locale}`
);
if (pathnameIsMissingLocale) {
const locale = getLocale(request);
return NextResponse.redirect(
new URL(`/${locale}/${pathname}`, request.url)
);
}
}
export const config = {
matcher: [
// Skip all internal paths (_next, assets, api)
//"/((?!api|assets|.*\\..*|_next).*)",
"/((?!api|assets|docs|.*\\..*|_next).*)",
// Optional: only run on root (/) URL
],
};
In this application, I want to implement authentication using auth.js v5. According to the docs, I have to add the below snippet in the middleware without any matcher.
import { auth as middleware } from "@/lib/auth";
How to resolve this issue? TIA
Renaming one of the functions doesn't help as it has to be middleware for it work.