A Microcosm of the Macrocosm
A Microcosm of the Macrocosm
BABetter Auth
Created by A Microcosm of the Macrocosm on 4/13/2025 in #help
Custom Tables | SQL Schema
I don't even get to generate the schema having the additional field typed like that ["AP", "HF"]. I get the error I mentioned above. However, now that I think about it... TypeScript itself doesn't error out on that [on type: ["AP", "HF"]]. So, if I just don't run the better-auth cli to generate the schema, then there we go, problem solved, hah. No BA CLI schema generation,no error😂 .
14 replies
BABetter Auth
Created by A Microcosm of the Macrocosm on 4/13/2025 in #help
Custom Tables | SQL Schema
I'd be okay with the type hinting, at least, since these are the two values I'd expect and enforce. For the actual types, I'd infer them from the edited table schemas. The thing is I can't even type the additional field with ["AP", "HF"]. Maybe I'll have to just type it with string and then edit the generated schema - create the pgEnum and properly type the table field. I just don't know if better-auth is going to be okay with that
14 replies
BABetter Auth
Created by A Microcosm of the Macrocosm on 4/13/2025 in #help
Custom Tables | SQL Schema
By using type: "string[]", I don't get the error and the generated schema has user_type: text('user_type').array(), but that isn't what I wanted. I wanted it to be mapped to an enum with the coupla values possible.
14 replies
BABetter Auth
Created by A Microcosm of the Macrocosm on 4/13/2025 in #help
Custom Tables | SQL Schema
Error:
$ bunx @better-auth/cli generate --output ./server/database/schemata/auth-schema.ts
preparing schema...file:///tmp/bunx-1000-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:467
return typeMap[type][databaseType];
^

TypeError: Cannot read properties of undefined (reading 'pg')
at getType (file:///tmp/bunx-1000-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:467:27)
at file:///tmp/bunx-1000-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:490:27
at Array.map (<anonymous>)
at generateDrizzleSchema (file:///tmp/bunx-1000-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:488:28)
at getGenerator (file:///tmp/bunx-1000-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:710:10)
at Command.generateAction (file:///tmp/bunx-1000-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:740:24)
$ bunx @better-auth/cli generate --output ./server/database/schemata/auth-schema.ts
preparing schema...file:///tmp/bunx-1000-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:467
return typeMap[type][databaseType];
^

TypeError: Cannot read properties of undefined (reading 'pg')
at getType (file:///tmp/bunx-1000-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:467:27)
at file:///tmp/bunx-1000-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:490:27
at Array.map (<anonymous>)
at generateDrizzleSchema (file:///tmp/bunx-1000-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:488:28)
at getGenerator (file:///tmp/bunx-1000-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:710:10)
at Command.generateAction (file:///tmp/bunx-1000-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:740:24)
14 replies
BABetter Auth
Created by A Microcosm of the Macrocosm on 4/13/2025 in #help
Custom Tables | SQL Schema
@bekacru Sorry for the ping, but... ... using a string literal array [as you suggested] for a type [so it can be mapped to a pg enum], I get an error when I try to generate the schema via the BA CLI My auth object looks like
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { useDrizzle as db } from "../server/utils/drizzle"; // Drizzle instance
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
}),
user: {
additionalFields: {
user_type: {
type: ["AP", "HF"],
},
},
},
emailAndPassword: {
enabled: true,
},
});
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { useDrizzle as db } from "../server/utils/drizzle"; // Drizzle instance
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
}),
user: {
additionalFields: {
user_type: {
type: ["AP", "HF"],
},
},
},
emailAndPassword: {
enabled: true,
},
});
14 replies
BABetter Auth
Created by A Microcosm of the Macrocosm on 4/13/2025 in #help
Custom Tables | SQL Schema
Fascinating. THANK YOU VERY MUCH. I'll work on my Nuxt Project setup then. If you need any help, please let us know how we can help you out. Thank you.
14 replies
BABetter Auth
Created by A Microcosm of the Macrocosm on 4/13/2025 in #help
Custom Tables | SQL Schema
Thank you very much. Lemme see if I got this straight: 1. for the custom tables, I can create them on the database and that's all. I don't need to tell better-auth about them via a custom plugin, stating the extra tables, etc., right? 2. regarding the user table, it will have an additional field (user_type), I'll add that to the user's additionalFields when setting up the auth instance. For the type of this user_type I didn't get to set string[] or Array<LiteralString>. Could you help me out saying what exactly I need to type the user_type with? 3. Okay. For the ids, I'll just have them as uuid, to be default generated with get_random_uuid(), and disable better-auth's default id generation when setting up the auth object.
14 replies