-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
77 lines (66 loc) · 1.83 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { NextRequest, NextResponse } from 'next/server';
import createIntlMiddleware from 'next-intl/middleware';
import { auth } from "./auth";
import { intlConfig } from "@/messages/config";
const { locales, defaultLocale, localePrefix } = intlConfig;
/*
const publicRoutes = [
'/',
'/books',
'/privacy-policy',
'/terms-of-service',
'/signin',
];
*/
const intlMiddleware = createIntlMiddleware({
locales,
defaultLocale,
localePrefix
});
/*
const authMiddleware = auth((req) => {
// private routes here
const session = req.auth
if (session) {
return intlMiddleware(req)
} else {
// Determine the locale for redirection
const url = req.nextUrl.clone();
const localePath = url.locale ? `/${url.locale}` : '';
const signInPath = `${localePath}/signin`;
url.pathname = signInPath;
// Redirect to the localized sign-in page if no session is found
return NextResponse.redirect(url);
}
})
*/
export default function middleware(req: NextRequest) {
/*
const publicPathnameRegex = RegExp(
`^(/(${locales.join("|")}))?(/book/[^/]+|/book/[^/]+/summary|/book/[^/]+/read|/books/[^/]+|${publicRoutes.flatMap((p) => {
if (p === "/") {
return ["", "/"]; // Root path handled separately for optional trailing slash
}
// Ensure all other routes and their trailing slash variations are matched
return [p, `${p}/?`];
}).join("|")})/?$`,
"i"
);
const isPublicPage = publicPathnameRegex.test(req.nextUrl.pathname)
if (isPublicPage) {
return intlMiddleware(req)
} else {
return (authMiddleware as any)(req)
}
*/
return intlMiddleware(req)
}
export const config = {
matcher: [
'/((?!api|_next/static|_next/image|favicon.ico).*)',
// '/book/:bookId',
// '/book/:bookId/summary',
// '/book/:bookId/read',
// '/books/:userId',
],
}