#add additional field to auth user table

3 messages · Page 1 of 1 (latest)

modern spokeBOT
#

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

#

To add an additional field like isPublic: boolean to your users table in Convex Auth, you need to inline the users table definition and add your custom field. Here’s how you can do it:

import { defineSchema, defineTable } from "convex/server";
import { v } from "convex/values";
import { authTables } from "@convex-dev/auth/server";

const schema = defineSchema({
  ...authTables,
  users: defineTable({
    // Existing fields from the default users table
    name: v.optional(v.string()),
    image: v.optional(v.string()),
    email: v.optional(v.string()),
    emailVerificationTime: v.optional(v.number()),
    phone: v.optional(v.string()),
    phoneVerificationTime: v.optional(v.number()),
    isAnonymous: v.optional(v.boolean()),
    // Your additional field
    isPublic: v.boolean(),
  }).index("email", ["email"]),
  // Your other tables...
});

export default schema;

Key points:

  • Inline the users table definition and add your custom field (isPublic: v.boolean()).
  • If you want isPublic to be required, make sure all authentication methods provide this field during sign-up. Otherwise, make it optional with v.optional(v.boolean()) to avoid schema validation errors if the field is missing during user creation Customizing Schema.

This approach is the recommended way to extend the users table with additional fields in Convex Auth.

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

#

@void sigil Kapa.ai is still learning and improving, please let me know how I did by reacting below.