-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
35 lines (28 loc) · 979 Bytes
/
middleware.ts
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
30
31
32
33
34
35
import { locales, routing } from "@/i18n/routing";
import { updateSession } from "@/lib/supabase/middlewares/update-session";
import createMiddleware from "next-intl/middleware";
import { type NextRequest } from "next/server";
const publicPages = [
/\//,
/\/sign-in/,
/\/sign-up/,
/\/dashboard\/lessons\/[\w-]+/,
];
const intlMiddleware = createMiddleware(routing);
export async function middleware(request: NextRequest) {
const publicPathnameRegex = new RegExp(
`^(/(${locales.join("|")}))?(${publicPages.map((page) => page.source).join("|")})$`,
"i"
);
const isPublicPage = publicPathnameRegex.test(request.nextUrl.pathname);
// Run the intlMiddleware first to ensure locale is set
const response = intlMiddleware(request);
if (isPublicPage) {
return response;
}
return updateSession(request, response);
// Update session with the response from intlMiddleware
}
export const config = {
matcher: ["/((?!api|_next|.*\\..*).*)"],
};