-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.ts
34 lines (31 loc) · 1.33 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
import { redirectToSignIn } from "@clerk/nextjs";
import { authMiddleware } from "@clerk/nextjs/server";
import { redirect } from "next/navigation";
import { NextResponse } from "next/server";
// This example protects all routes including api/trpc routes
// Please edit this to allow other routes to be public as needed.
// See https://clerk.com/docs/references/nextjs/auth-middleware for more information about configuring your Middleware
export default authMiddleware({
publicRoutes: [`/`,`/api/uploadthing`,`/api/uploadthing-multi`,`/api/livekit/`],
afterAuth(auth, req, evt) {
// Handle users who aren't authenticated
if (!auth.userId && !auth.isPublicRoute) {
console.log(req.url)
const port = process.env.PORT
if(port=="10000")
return redirectToSignIn({ returnBackUrl: "https://liltrees.onrender.com/check-auth" });
else
return redirectToSignIn({ returnBackUrl: req.url });
}
// If the user is signed in and trying to access a protected route, allow them to access route
if (auth.userId && !auth.isPublicRoute) {
return NextResponse.next();
}
// Allow users visiting public routes to access them
return NextResponse.next();
},
// debug: true
});
export const config = {
matcher: ["/((?!.+\\.[\\w]+$|_next|_next/image|favicon.ico).*)", "/", "/(api|trpc)(.*)",]
};