This commit is contained in:
+9
-1
@@ -3,6 +3,7 @@ import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
import { routing } from "./i18n/routing";
|
||||
import { getLocalizedPath } from "./lib/locale";
|
||||
|
||||
const intlMiddleware = createMiddleware(routing);
|
||||
const ADMIN_SESSION_COOKIE = "moh_admin_session";
|
||||
@@ -139,6 +140,13 @@ export default async function middleware(request: NextRequest) {
|
||||
const isRootBaseRoute = pathname === "/root" || pathname.startsWith("/root/");
|
||||
const isRootRoute = isRootBaseRoute;
|
||||
|
||||
if (pathname === "/de" || pathname.startsWith("/de/")) {
|
||||
const redirectUrl = request.nextUrl.clone();
|
||||
const nextPath = pathname.slice(3) || "/";
|
||||
redirectUrl.pathname = nextPath;
|
||||
return NextResponse.redirect(redirectUrl, 308);
|
||||
}
|
||||
|
||||
if (isRootRoute && isRootBasicAuthConfigured() && !isRootBasicAuthValid(request)) {
|
||||
return new NextResponse("Authentication required", {
|
||||
status: 401,
|
||||
@@ -164,7 +172,7 @@ export default async function middleware(request: NextRequest) {
|
||||
if (!isAdminAuthenticated) {
|
||||
const targetLocale = locale ?? routing.defaultLocale;
|
||||
const redirectUrl = request.nextUrl.clone();
|
||||
redirectUrl.pathname = `/${targetLocale}/coming-soon`;
|
||||
redirectUrl.pathname = getLocalizedPath(targetLocale, "/coming-soon");
|
||||
redirectUrl.search = "";
|
||||
return NextResponse.redirect(redirectUrl);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user