Skip to content

Commit

Permalink
feat(web/api/webhook): user update handle
Browse files Browse the repository at this point in the history
  • Loading branch information
mrevanzak committed Dec 22, 2023
1 parent 01bfcfb commit 7012619
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions apps/nextjs/src/app/api/webhook/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,22 @@ export async function POST(req: Request) {
status: 400,
});
}
await db.insert(users).values({
id,
email: emailObject.email_address,
name: `${evt.data.first_name} ${evt.data.last_name ?? ""}`,
imageUrl: evt.data.image_url,
});

eventType === "user.created"
? await db.insert(users).values({
id,
email: emailObject.email_address,
name: `${evt.data.first_name} ${evt.data.last_name ?? ""}`,
imageUrl: evt.data.image_url,
})
: await db
.update(users)
.set({
email: emailObject.email_address,
name: `${evt.data.first_name} ${evt.data.last_name ?? ""}`,
imageUrl: evt.data.image_url,
})
.where(eq(users.id, id));
}
if (eventType === "user.deleted") {
await db.delete(users).where(eq(users.id, id));
Expand Down

0 comments on commit 7012619

Please sign in to comment.