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

Fix bug in Clerk webhook: ensure user creation in Convex DB for email signups without first name #8

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

deepsingh132
Copy link
Owner

Pull Request Description

Bug Fix: Ensure User Creation in Convex DB for Clerk Email Signups Without First Name

This PR addresses a critical bug in the Clerk webhook where users signing up with only an email and no provided first name were not being created in the Convex database. The issue stemmed from a forced assertion (event.data.first_name!) on the first_name field, which caused an error when first_name was null or undefined, halting user creation.

Changes

  • Before:

    name: event.data.first_name!

    This code assumed that first_name was always provided, causing issues when first_name was missing.

  • After:

    name: event.data.first_name
      ? event.data.first_name + " " + (event.data.last_name ?? "")
      : event.data.email_addresses[0].email_address.split("@")[0]

    Now, if first_name is missing, the code assigns name to the username derived from the email prefix. This ensures that all users, even those signing up without a first name, are created in the database.

This fix provides a fallback mechanism for name, improving robustness and ensuring successful user creation for all signups.

Copy link

vercel bot commented Nov 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
aionair ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 14, 2024 10:48am

@deepsingh132
Copy link
Owner Author

LGTM 👍

@deepsingh132 deepsingh132 merged commit 380ad15 into main Nov 14, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant