kstulgys
kstulgys5mo ago

Convex auth does not work with defineEntSchema

is there a way to make it work? My entire project schema is using defineEntSchema and not the defineSchema
No description
8 Replies
kstulgys
kstulgysOP5mo ago
wow i think tis works.. can anyone who is smarter confirm? const merged = defineSchema({ ...schema.tables, ...authSchema.tables });
appixel.dev
appixel.dev5mo ago
This is working for me but i'm not sure it's ideal way though. const schema = defineEntSchema( { authAccounts: defineEntFromTable(authTables.authAccounts), authRefreshTokens: defineEntFromTable(authTables.authRefreshTokens), authSessions: defineEntFromTable(authTables.authSessions), authVerificationCodes: defineEntFromTable(authTables.authVerificationCodes), authRateLimits: defineEntFromTable(authTables.authRateLimits), authVerifiers: defineEntFromTable(authTables.authVerifiers),
Michal Srb
Michal Srb5mo ago
I'll add this to Ents soon, for now you can inline:
type DefineEntFromTables<
T extends { [key: string]: TableDefinition<any, any, any, any> },
> = {
[K in keyof T]: T[K] extends TableDefinition<
infer D,
infer I,
infer S,
infer V
>
? EntDefinition<D, I, S, V>
: never;
};

function defineEntsFromTables<
T extends { [key: string]: TableDefinition<any, any, any, any> },
>(definitions: T): DefineEntFromTables<T> {
const result: any = {};
for (const key in definitions) {
result[key] = defineEntFromTable(definitions[key]);
}
return result;
}


const schema = defineEntSchema({
...defineEntsFromTables(authTables),
users: defineEnt({
name: v.optional(v.string()),
image: v.optional(v.string()),
emailVerificationTime: v.optional(v.number()),
phone: v.optional(v.string()),
phoneVerificationTime: v.optional(v.number()),
isAnonymous: v.optional(v.boolean()),
}),
//...etc
});
type DefineEntFromTables<
T extends { [key: string]: TableDefinition<any, any, any, any> },
> = {
[K in keyof T]: T[K] extends TableDefinition<
infer D,
infer I,
infer S,
infer V
>
? EntDefinition<D, I, S, V>
: never;
};

function defineEntsFromTables<
T extends { [key: string]: TableDefinition<any, any, any, any> },
>(definitions: T): DefineEntFromTables<T> {
const result: any = {};
for (const key in definitions) {
result[key] = defineEntFromTable(definitions[key]);
}
return result;
}


const schema = defineEntSchema({
...defineEntsFromTables(authTables),
users: defineEnt({
name: v.optional(v.string()),
image: v.optional(v.string()),
emailVerificationTime: v.optional(v.number()),
phone: v.optional(v.string()),
phoneVerificationTime: v.optional(v.number()),
isAnonymous: v.optional(v.boolean()),
}),
//...etc
});
kstulgys
kstulgysOP5mo ago
wow thank you
Michal Srb
Michal Srb5mo ago
Docs: https://labs.convex.dev/convex-ents/auth with convex-ents@0.8.1
Authentication - Convex Ents
Relations, default values, unique fields and more for Convex
xEagle
xEagle5mo ago
Hello, I met this error. Could anybody help me?
No description
Michal Srb
Michal Srb5mo ago
Manual Setup - Convex Auth
Authentication library for your Convex backend
xEagle
xEagle5mo ago
Thank you very much.👍

Did you find this page helpful?