Skip to content
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

Open
4 tasks done
LuccaRebelloToledo opened this issue Feb 6, 2025 · 2 comments
Open
4 tasks done
Labels
needs-triage A ticket that needs to be triaged by a team member

Comments

@LuccaRebelloToledo
Copy link

LuccaRebelloToledo commented Feb 6, 2025

Preliminary Checks

Reproduction

Zip

Publishable key

pk_test_c2V0LXR1bmEtNzUuY2xlcmsuYWNjb3VudHMuZGV2JA

Description

Steps to reproduce:

  1. Create a Webhook with Event Types (user.created or user.updated).
  2. Receive the UserJSON from the webhook.
  3. Attempt to parse UserJSON into User.

Expected behavior:

The UserJSON should successfully convert into a User object.

Actual behavior:

An error occurs:

'User' cannot be used as a value because it was exported using 'export type'.
index.d.ts(28, 283): 'User' was exported here.

clerk-use-case.zip

Environment

System:
    OS: Windows 11 10.0.26100
    CPU: (16) x64 AMD Ryzen 7 5700X3D 8-Core Processor
    Memory: 18.42 GB / 31.93 GB
  Binaries:
    Node: 22.13.0 - C:\nvm4w\nodejs\node.EXE
    npm: 11.0.0 - C:\nvm4w\nodejs\npm.CMD
    pnpm: 9.15.4 - C:\nvm4w\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (131.0.2903.146)
  npmPackages:
    @clerk/express: ^1.3.31 => 1.3.31
@LuccaRebelloToledo LuccaRebelloToledo added the needs-triage A ticket that needs to be triaged by a team member label Feb 6, 2025
@LuccaRebelloToledo LuccaRebelloToledo changed the title Bug Report: Error When Parsing UserJSON to User [@clerk/backend] Bug Report: Error When Parsing UserJSON to User Feb 7, 2025
@LuccaRebelloToledo LuccaRebelloToledo changed the title [@clerk/backend] Bug Report: Error When Parsing UserJSON to User [@clerk/express] Bug Report: Error When Parsing UserJSON to User Feb 7, 2025
@Nelwhix
Copy link

Nelwhix commented Feb 11, 2025

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");
  }
});

@LuccaRebelloToledo
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage A ticket that needs to be triaged by a team member
Projects
None yet
Development

No branches or pull requests

2 participants