Skip to content

Commit 6664581

Browse files
committedSep 23, 2024·
add api/webhooks to public routes
1 parent 158f369 commit 6664581

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed
 

‎app/api/webhook/route.ts renamed to ‎app/api/webhooks/route.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,18 @@ export async function POST(req: Request) {
5858
const { id, email_addresses, image_url, username, first_name, last_name } =
5959
evt.data;
6060

61+
// const mongoUser = await createUser({
62+
// clerkId: id,
63+
// name: `${first_name}${last_name ? ` ${last_name}` : ""}`,
64+
// username: username!,
65+
// email: email_addresses[0].email_address,
66+
// picture: image_url,
67+
// });
68+
6169
const mongoUser = await createUser({
6270
clerkId: id,
63-
name: `${first_name}${last_name ? ` ${last_name}` : ""}`,
64-
username: username!,
71+
name: `${first_name}${last_name ? `${last_name}` : ""}`,
72+
username: username || "Userx",
6573
email: email_addresses[0].email_address,
6674
picture: image_url,
6775
});

‎middleware.ts

+5-23
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,19 @@
1616
// ],
1717
// };
1818
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
19+
const isProtectedRoute = createRouteMatcher(["/ask-question(.*)"]);
1920

20-
const isPublicRoute = createRouteMatcher([
21-
"/",
22-
"/api/webhook",
23-
"/question/:id)",
24-
"/tags(.*)",
25-
"/tags/:id",
26-
"/profile/:id",
27-
"/community",
28-
"/jobs",
29-
"/sign-in(.*)",
30-
"/sign-up(.*)",
31-
]);
32-
33-
const isIgnoredRoute = createRouteMatcher(["/api/webhook", "/api/chatgpt"]);
34-
35-
export default clerkMiddleware((auth, request) => {
36-
const { pathname } = new URL(request.url);
37-
38-
if (isIgnoredRoute(request)) {
39-
return;
40-
}
41-
42-
if (!isPublicRoute(request)) {
21+
export default clerkMiddleware((auth, req) => {
22+
if (isProtectedRoute(req)) {
4323
auth().protect();
4424
}
4525
});
4626

4727
export const config = {
4828
matcher: [
29+
// Skip Next.js internals and all static files, unless found in search params
4930
"/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)",
31+
// Always run for API routes
5032
"/(api|trpc)(.*)",
5133
],
5234
};

‎next.config.mjs

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ const nextConfig = {
55
mdxRs: true,
66
serverComponentsExternalPackages: ["mongoose"],
77
},
8+
images: {
9+
remotePatterns: [
10+
{
11+
protocol: "https",
12+
hostname: "img.clerk.com",
13+
},
14+
],
15+
},
816
};
917

1018
export default nextConfig;

0 commit comments

Comments
 (0)
Please sign in to comment.