#Setting a table column to have the same type as clerkJs' user id.

3 messages · Page 1 of 1 (latest)

uneven blade
#

In our convex database schema, is it possible to set a field's type to the same type as clerkJs' user id? I've integrated convex with clerk but I'm wondering if I can create this dependency to ensure that the database stays clean

olive nexusBOT
#

Hi @uneven blade. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

You can set a field in your Convex schema to store Clerk's user ID, but you cannot directly enforce the type to be "Clerk user ID"—you can only specify the field as a string. Clerk user IDs are strings, so in your Convex schema, you would define the field as v.string(). For example:

users: defineTable({
  name: v.string(),
  externalId: v.string(), // This stores the Clerk user ID
}).index("byExternalId", ["externalId"]),

This is the recommended approach when integrating Convex with Clerk. The Convex documentation and examples use a string field (often called externalId or tokenIdentifier) to store the Clerk user ID, and you can add an index for efficient lookups. There is no built-in validator in Convex that enforces the format of Clerk user IDs specifically, but using v.string() ensures the field is always a string, which matches Clerk's user ID type. You can add additional validation in your application logic if you want to enforce a specific format or pattern for Clerk IDs, but this is not handled at the schema level by Convex itself.

References:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: