pollo/src/middleware.ts

22 lines
630 B
TypeScript
Raw Normal View History

2023-08-12 17:12:42 -06:00
import { authMiddleware } from "@clerk/nextjs";
2023-08-17 16:40:09 -06:00
import { validateRequest } from "./server/unkey";
import { NextResponse } from "next/server";
2023-08-12 17:12:42 -06:00
export default authMiddleware({
publicRoutes: ["/", "/api/(.*)"],
2023-08-17 16:40:09 -06:00
beforeAuth: async (req) => {
if (req.nextUrl.pathname.startsWith("/api/external")) {
const isValid = await validateRequest(req);
console.log("Is Valid?: ", isValid);
if (isValid) {
return NextResponse.next();
}
return new NextResponse("UNAUTHORIZED", { status: 403 });
}
},
2023-08-12 17:12:42 -06:00
});
export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};