38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { NextMiddleware } from "next/server"
|
|
|
|
import * as authRequired from "./middlewares/authRequired"
|
|
import * as cmsContent from "./middlewares/cmsContent"
|
|
import * as currentWebLogin from "./middlewares/currentWebLogin"
|
|
import * as ensureLang from "./middlewares/ensureLang"
|
|
import * as handleAuth from "./middlewares/handleAuth"
|
|
import * as webView from "./middlewares/webView"
|
|
|
|
export const middleware: NextMiddleware = async (request, event) => {
|
|
const middlewares = [
|
|
ensureLang,
|
|
currentWebLogin,
|
|
authRequired,
|
|
handleAuth,
|
|
webView,
|
|
cmsContent,
|
|
]
|
|
|
|
for (let i = 0; i < middlewares.length; ++i) {
|
|
const middleware = middlewares[i]
|
|
|
|
if (middleware.matcher(request)) {
|
|
return await middleware.middleware(request, event)
|
|
}
|
|
}
|
|
}
|
|
|
|
// See "Matching Paths" below to learn more
|
|
export const config = {
|
|
/**
|
|
* Copied from Clerk to protect all routes by default and handle
|
|
* public routes inside middleware.
|
|
* (https://clerk.com/docs/quickstarts/nextjs?utm_source=sponsorship&utm_medium=youtube&utm_campaign=code-with-antonio&utm_content=12-31-2023#add-authentication-to-your-app)
|
|
*/
|
|
matcher: ["/((?!.+\\.[\\w]+$|_next|.netlify|en/test|api|trpc).*)"],
|
|
}
|