BA
Better Auth•21h ago
Firro

Seeding doesnt work

GitHub
better-auth/packages/better-auth/src/adapters/create-adapter/index....
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
12 Replies
Firro
FirroOP•21h ago
Changing the table name for the organization table also didnt work with:
Error seeding "organizationMember" in model organizationMember:
TypeError: Cannot read properties of undefined (reading 'modelName')
Error seeding "organizationMember" in model organizationMember:
TypeError: Cannot read properties of undefined (reading 'modelName')
Ping
Ping•20h ago
Do you have a need where the id must be predefined?
Firro
FirroOP•18h ago
That's where it gets manually created. Makes sense why, easier to create an ID sync and prepare all to be inserted objects first, but it does make it not work anymore. Probably just something that got in due to a refactor 2 weeks ago
Ping
Ping•17h ago
Hey do you have any logs or more info to share? I tried it on my end and it works.
Ping
Ping•17h ago
Just using something like this:
No description
Ping
Ping•17h ago
On latest Better-auth. I'll test this now.
Ping
Ping•17h ago
Seeding organization works with custom organization model name too 🤔
No description
Ping
Ping•17h ago
No description
Firro
FirroOP•12h ago
Hey, sorry, fell asleep. Weird that it works for you so easily. I don't have the file anymore but I was seeding users, orgs etc. I'll create my setup again seed.ts:
import { $, organizations, Seed, users } from "@better-auth-kit/seed";

export const seed = Seed({
// Adds 100 users (including sessions and accounts)
...users(
{
user: {
name: $.first_and_lastname(),
// @ts-expect-error This exists
firstName: $.firstname(),
lastName: $.lastname(),
email: $.email(),
},
},
{
count: 100,
}
),
...organizations(
{},
{
modelNames: {
organization: "organization",
member: "organization_member",
invitation: "organization_invitation",
team: "organization_team",
},
}
),
});
import { $, organizations, Seed, users } from "@better-auth-kit/seed";

export const seed = Seed({
// Adds 100 users (including sessions and accounts)
...users(
{
user: {
name: $.first_and_lastname(),
// @ts-expect-error This exists
firstName: $.firstname(),
lastName: $.lastname(),
email: $.email(),
},
},
{
count: 100,
}
),
...organizations(
{},
{
modelNames: {
organization: "organization",
member: "organization_member",
invitation: "organization_invitation",
team: "organization_team",
},
}
),
});
auth.ts
export const authBasePath = "/auth";

export const auth = betterAuth({
basePath: authBasePath,
appName: "bla",
database: drizzleAdapter(db, {
provider: "pg",
}),
user: {
additionalFields: {
firstName: {
type: "string",
required: false,
input: true,
},
lastName: {
type: "string",
required: false,
input: true,
},
},
},
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
},
emailVerification: {
autoSignInAfterVerification: true,
sendOnSignUp: true,
},
socialProviders: {
google: {
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
mapProfileToUser: (profile) => {
return {
firstName: profile.given_name,
lastName: profile.family_name,
};
},
},
},
account: {
accountLinking: {
enabled: true,
},
},
plugins: [
admin(),
apiKey(),
organization({
schema: {
member: {
modelName: "organizationMember",
},
},
}),
],
});
export const authBasePath = "/auth";

export const auth = betterAuth({
basePath: authBasePath,
appName: "bla",
database: drizzleAdapter(db, {
provider: "pg",
}),
user: {
additionalFields: {
firstName: {
type: "string",
required: false,
input: true,
},
lastName: {
type: "string",
required: false,
input: true,
},
},
},
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
},
emailVerification: {
autoSignInAfterVerification: true,
sendOnSignUp: true,
},
socialProviders: {
google: {
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
mapProfileToUser: (profile) => {
return {
firstName: profile.given_name,
lastName: profile.family_name,
};
},
},
},
account: {
accountLinking: {
enabled: true,
},
},
plugins: [
admin(),
apiKey(),
organization({
schema: {
member: {
modelName: "organizationMember",
},
},
}),
],
});
@better-auth-kit/[email protected] [email protected] Thanks for the library btw, appreciate the work!
Ping
Ping•5h ago
@Firro Are you able to remove modelNames in the organization options part? The seed tool will pick up on your auth config defined modelName for organization In saying that, I will probably remove that modelNames part given such ^ I just tried to seed using the same user configuration as you and it works 🤔
Ping
Ping•5h ago
Also here's a cool tip: You can define the generics for the seed helpers to not get type errors if certain tables have rows that are not default to BetterAuth, eg:
No description

Did you find this page helpful?