Webhook updates

This commit is contained in:
Atridad Lahiji 2023-08-14 12:46:27 -06:00
parent f3485ff055
commit cfda805a95
No known key found for this signature in database
2 changed files with 59 additions and 2 deletions

View file

@ -0,0 +1,55 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { env } from "~/env.mjs";
import { validateRequest } from "~/server/unkey";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const success = await validateRequest(req, res);
if (success) {
const requestBody = req.body as {
data: {
id: string;
email_addresses: [
{
email_address: string;
id: string;
verification: {
status: string;
strategy: string;
};
}
];
};
object: string;
type: string;
};
const userUpdateResponse = await fetch(
`https://api.clerk.com/v1/users/${requestBody.data.id}/metadata`,
{
method: "PATCH",
headers: {
Authorization: `Bearer ${env.CLERK_SECRET_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
public_metadata: {
isVIP: false,
isAdmin: false,
},
private_metadata: {},
unsafe_metadata: {},
}),
}
);
if (userUpdateResponse.status === 200) {
res.status(200).json({ result: "METADATA UPDATED" });
} else {
res.status(500).json({ error: "ERROR UPDATING METADATA" });
}
}
}

View file

@ -28,8 +28,10 @@ export default async function handler(
if (deletedRoom.rowsAffected > 0) {
await db.delete(logs).where(eq(logs.userId, requestBody.data.id));
await db.delete(votes).where(eq(votes.userId, requestBody.data.id));
}
res.status(200).json({ result: "USER DELETED" });
} else {
res.status(500).json({ result: "ERROR DELETING USER" });
}
}
}