#Setting a table column to have the same type as clerkJs' user id.
3 messages · Page 1 of 1 (latest)
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:
- Convex Auth + Clerk: storing user IDs as strings
- Schema example with externalId as string
- Discussion on storing Clerk IDs in Convex