Skip to content

Commit 0f9a765

Browse files
clerk and vercel
1 parent 6664581 commit 0f9a765

File tree

2 files changed

+12
-35
lines changed

2 files changed

+12
-35
lines changed

app/api/webhooks/route.ts

+12-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createUser, deleteUser, updateUser } from "@/lib/actions/user.action";
55
import { NextResponse } from "next/server";
66

77
export async function POST(req: Request) {
8-
// You can find this in the Clerk Dashboard -> Webhooks -> choose the endpoint
8+
// You can find this in the Clerk Dashboard -> Webhooks -> choose the webhook
99
const WEBHOOK_SECRET = process.env.NEXT_CLERK_WEBHOOK_SECRET;
1010

1111
if (!WEBHOOK_SECRET) {
@@ -31,7 +31,7 @@ export async function POST(req: Request) {
3131
const payload = await req.json();
3232
const body = JSON.stringify(payload);
3333

34-
// Create a new Svix instance with your secret.
34+
// Create a new SVIX instance with your secret.
3535
const wh = new Webhook(WEBHOOK_SECRET);
3636

3737
let evt: WebhookEvent;
@@ -50,36 +50,29 @@ export async function POST(req: Request) {
5050
});
5151
}
5252

53-
// Do something with the payload
54-
// For this guide, you simply log the payload to the console
5553
const eventType = evt.type;
5654

5755
if (eventType === "user.created") {
5856
const { id, email_addresses, image_url, username, first_name, last_name } =
5957
evt.data;
6058

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-
59+
// Create a new user in your database
6960
const mongoUser = await createUser({
7061
clerkId: id,
71-
name: `${first_name}${last_name ? `${last_name}` : ""}`,
72-
username: username || "Userx",
62+
name: `${first_name}${last_name ? ` ${last_name}` : ""}`,
63+
username: username!,
7364
email: email_addresses[0].email_address,
7465
picture: image_url,
7566
});
7667

77-
return NextResponse.json({ message: "Ok", user: mongoUser });
68+
return NextResponse.json({ message: "OK", user: mongoUser });
7869
}
70+
7971
if (eventType === "user.updated") {
8072
const { id, email_addresses, image_url, username, first_name, last_name } =
8173
evt.data;
8274

75+
// Create a new user in your database
8376
const mongoUser = await updateUser({
8477
clerkId: id,
8578
updateData: {
@@ -91,7 +84,7 @@ export async function POST(req: Request) {
9184
path: `/profile/${id}`,
9285
});
9386

94-
return NextResponse.json({ message: "Ok", user: mongoUser });
87+
return NextResponse.json({ message: "OK", user: mongoUser });
9588
}
9689

9790
if (eventType === "user.deleted") {
@@ -100,8 +93,9 @@ export async function POST(req: Request) {
10093
const deletedUser = await deleteUser({
10194
clerkId: id!,
10295
});
103-
return NextResponse.json({ message: "Ok", user: deletedUser });
96+
97+
return NextResponse.json({ message: "OK", user: deletedUser });
10498
}
10599

106-
return new Response("", { status: 200 });
100+
return NextResponse.json({ message: "OK" });
107101
}

middleware.ts

-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
// import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
2-
3-
// const isPublicRoute = createRouteMatcher(["/sign-in(.*)", "/sign-up(.*)"]);
4-
5-
// export default clerkMiddleware((auth, request) => {
6-
// const { pathname } = new URL(request.url);
7-
// if (pathname !== "/" && !isPublicRoute(request)) {
8-
// auth().protect();
9-
// }
10-
// });
11-
12-
// export const config = {
13-
// matcher: [
14-
// "/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)",
15-
// "/(api|trpc)(.*)",
16-
// ],
17-
// };
181
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
192
const isProtectedRoute = createRouteMatcher(["/ask-question(.*)"]);
203

0 commit comments

Comments
 (0)