forked from all-in-aigc/aiwallpaper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
26 lines (22 loc) · 731 Bytes
/
middleware.ts
File metadata and controls
26 lines (22 loc) · 731 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
import { NextResponse } from "next/server";
import { authMiddleware } from "@clerk/nextjs";
export default authMiddleware({
publicRoutes: ["/", "/pricing", "/api/get-wallpapers", "/api/get-user-info"],
afterAuth(auth, req, evt) {
if (!auth.userId && !auth.isPublicRoute) {
if (auth.isApiRoute) {
return NextResponse.json(
{ code: -2, message: "no auth" },
{ status: 401 }
);
} else {
console.log(`rewrite to sign-in ${new URL("/sign-in", req.url)}`);
return NextResponse.rewrite(new URL("/sign-in", req.url));
}
}
return NextResponse.next();
},
});
export const config = {
matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/", "/(api)(.*)"],
};