cameronm
cameronm5mo ago

Convex Auth user table fields

I've been looking for documentation on this with no avail. Querying the users table strips all the fields other than _createdTime, _id, name, email This is whether I used db.get or db.query. Any way around this? I set up a role field on my Password provider profile and added it to the user table, but it doesn't get returned by the query
11 Replies
Michal Srb
Michal Srb5mo ago
What does your schema look like? Did you check the data on your Convex dashboard?
cameronm
cameronmOP5mo ago
export default defineSchema({
...authTables,
users: defineTable({
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()),
role: v.optional(v.string()),
}),

...organizationsTable,
...contactTables,
});
export default defineSchema({
...authTables,
users: defineTable({
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()),
role: v.optional(v.string()),
}),

...organizationsTable,
...contactTables,
});
The data is unset for a lot of those on my test user. I might just create a user_profiles table with a link to the user to store my metadata about the user so I don't mess around with the auth tables too much
Michal Srb
Michal Srb5mo ago
Sounds like you're never setting role. What authentication methods are you using?
cameronm
cameronmOP5mo ago
Ah, it seems like unset fields are not returned. I thought it would return null?
Michal Srb
Michal Srb5mo ago
Unset fields are not returned. You can do v.union(v.null(), something) if you want nulls.
cameronm
cameronmOP5mo ago
I am using convex auth, and I am only using Password
Michal Srb
Michal Srb5mo ago
Then you'd want role to be returned by your profile callback.
cameronm
cameronmOP5mo ago
Ya, it is. But if it is unset, it isn't getting returned. Ok, so unset is not the same as null?
Michal Srb
Michal Srb5mo ago
Indeed
cameronm
cameronmOP5mo ago
Ok, so if I do want those as nulls, I have to define my schema to accept nulls, and set them to null using that after create callback or w.e Thanks I'll take a look at those docs

Did you find this page helpful?