-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmiddleware.ts
More file actions
39 lines (35 loc) · 926 Bytes
/
middleware.ts
File metadata and controls
39 lines (35 loc) · 926 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
30
31
32
33
34
35
36
37
38
39
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
import { NextResponse } from "next/server";
const protectedRoutes = createRouteMatcher([
"/",
"/upcoming",
"/previous",
"/recordings",
"/personal-room",
"/meeting(.*)",
]);
export default clerkMiddleware((auth, req) => {
if (protectedRoutes(req)) {
auth().protect();
}
});
export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*?)"],
};
export async function checkDbConnection() {
if (
typeof window === "undefined" &&
process.env.NODE_ENV !== "production"
) {
// Dynamically import the DB module only in non-production environments
const { connect, checkConnection } = await import("@/lib/db");
try {
if (!checkConnection()) {
await connect();
}
} catch (error) {
console.error("Database connection error:", error);
throw new Error("Failed to connect to the database");
}
}
}