-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
29 lines (23 loc) · 819 Bytes
/
middleware.ts
File metadata and controls
29 lines (23 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import createMiddleware from "next-intl/middleware";
import { NextRequest } from "next/server";
import { auth } from "@/lib/auth";
import { routing } from "./i18n/routing";
const publicPages = ["/", "/login"];
const handleI18nRouting = createMiddleware(routing);
const authMiddleware = auth((req) => {
return handleI18nRouting(req);
});
export default function middleware(req: NextRequest) {
const publicPathnameRegex = RegExp(
`^(/(${routing.locales.join("|")}))?(${publicPages
.flatMap((p) => (p === "/" ? ["", "/"] : p))
.join("|")})/?$`,
"i"
);
const isPublicPage = publicPathnameRegex.test(req.nextUrl.pathname);
if (isPublicPage) return handleI18nRouting(req);
else return (authMiddleware as any)(req);
}
export const config = {
matcher: ["/((?!api|_next|.*\\..*).*)"],
};