i want to disable route prefixing on /dashboard routes in my nextjs app.
here is my nextjs middleware.ts
const intlMiddleware = createMiddleware(routing);
export async function middleware(request: NextRequest) {
const session = (await auth()) as ExtendedSession | null;
const pathname = request.nextUrl.pathname;
const host = request.headers.get("host");
const wwwRegex = /^www./;
const isProduction = process.env.NODE_ENV === "production";
const isAdminPage = pathname.startsWith("/dashboard");
const isAuthPage = pathname.startsWith("/auth")
// other logics
if (isAdminPage) {
const session = (await auth()) as ExtendedSession | null;
if (!session || !session.user) {
return NextResponse.redirect(new URL("/", request.url));
}
if (!session.user.is_admin) {
return NextResponse.redirect(new URL("/", request.url));
}
return NextResponse.next();
}
// protect auth pages when user already logged in
if (isAuthPage) {
if (session && session.user) {
return NextResponse.redirect(new URL("/", request.url));
}
return NextResponse.next();
}
return intlMiddleware(request);
}
export const config = {
matcher: [
"/",
"/about-us",
"/tours",
"/tours/:path*",
"/privacy-policy",
"/terms-and-conditions",
"/private",
"/private/:path*",
"/private-packages",
"/dashboard",
"/dashboard/:path*",
"/auth/login",
'/(en|ru|de)/:path*',
// match middleware also to an old routes to run 301 redirects
"/kazbegi-gudauri2",
"/kaxeti-2",
"/mtskheta-jvari-gori-uplistsikhe2",
"/borjomi-rabati-vardzia2",
"/tbilisi-walking-tour2",
"/dashbashi-canyon2",
"/mtskheta-and-jvari-monastery2",
],
};
- first i try remove /dashboard from matcher but than i wass unable to check user is authorized or not when visiting dashboard pages
- second i try to return nextResponse when its dashboard page and return nextMiddleware when its other pages but error iss
Error: No intl context found. Have you configured the provider? See https://next-intl-docs.vercel.app/docs/usage/configuration#client-server-components