-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[@clerk/express] Bug Report: Error When Parsing UserJSON to User #5093
Comments
Hi @LuccaRebelloToledo, after reviewing the code I don't think the User type is meant to be used that way. It is probably provided for internal use. Is there a reason why you can't use the userEvent variable directly? but if you absolutely want to deal with user types what if you do it this way: import { clerkClient } from "@clerk/express";
app.post("/webhook", async (req, res) => {
try {
const userEvent = req.body;
console.log("User Event:", userEvent);
const userId = userEvent.id;
const user = await clerkClient.users.getUser(userId);
console.log("Fetched User:", user);
res.status(200).send("Webhook received");
} catch (error) {
console.error("Error processing webhook:", error);
res.status(500).send("Internal server error");
}
}); |
Hey @Nelwhix, how are you? In the project I'm working on, I use many methods that take the User type as a parameter. It would be unfeasible for me to convert all the methods to use UserJSON. Also, if there was an update, I would have to update twice :/ Therefore, converting JSON to the User class ends up being quite important to me and will minimize requests in Clerk, consequently reducing costs. |
Related to #5058 |
Hello @LuccaRebelloToledo! Sorry for the delay in getting back to you. After reviewing your issue and the related PR (#5058), I'd like to suggest a different approach. Instead of trying to convert the webhook payload into a For example, if your functions need specific user properties, you could do: app.post('/webhook', async (req, res) => {
const userData: UserJSON = req.body
// Extract only the properties you need
const { id, email_addresses, first_name, last_name } = userData
type UserData = {...}
// Pass this to your functions instead
const userInfo: UserData = {
userId: id,
emails: email_addresses,
firstName: first_name,
lastName: last_name
}
await handleUserAction(userInfo)
}) |
Preliminary Checks
I have reviewed the documentation: https://clerk.com/docs
I have searched for existing issues: https://github.com/clerk/javascript/issues
I have not already reached out to Clerk support via email or Discord (if you have, no need to open an issue here)
This issue is not a question, general help request, or anything other than a bug report directly related to Clerk. Please ask questions in our Discord community: https://clerk.com/discord.
Reproduction
Zip
Publishable key
pk_test_c2V0LXR1bmEtNzUuY2xlcmsuYWNjb3VudHMuZGV2JA
Description
Steps to reproduce:
Expected behavior:
The UserJSON should successfully convert into a User object.
Actual behavior:
An error occurs:
clerk-use-case.zip
Environment
The text was updated successfully, but these errors were encountered: