GenerateId false is not working

Even with generateId set to false, when I try to login I get the error because its trying to use its own id instead of the db's default
export function initAuth() {
if (authInstance) {
return authInstance;
}

authInstance = betterAuth({
database: drizzleAdapter(getDB(), {
debugLogs: true,
provider: "pg",
schema: {
user: users,
verification: verifications,
account: accounts,
session: sessions,
},
}),
trustedOrigins: ["http://localhost:3000"],
emailAndPassword: {
enabled: true,
},
advanced: {
cookiePrefix: "kipap",
database: {
generateId: false,
},
},
plugins: [expo() as BetterAuthPlugin],
});

logger.info("Auth initialized");

return authInstance;
}
export function initAuth() {
if (authInstance) {
return authInstance;
}

authInstance = betterAuth({
database: drizzleAdapter(getDB(), {
debugLogs: true,
provider: "pg",
schema: {
user: users,
verification: verifications,
account: accounts,
session: sessions,
},
}),
trustedOrigins: ["http://localhost:3000"],
emailAndPassword: {
enabled: true,
},
advanced: {
cookiePrefix: "kipap",
database: {
generateId: false,
},
},
plugins: [expo() as BetterAuthPlugin],
});

logger.info("Auth initialized");

return authInstance;
}
1 Reply
volks
volksOP4w ago
backend-1 | # SERVER_ERROR: error: invalid input syntax for type uuid: "SjqCWRUKZhI31p8tA8GYBdZhtWf171x3"
backend-1 | at /app/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11
...
backend-1 | length: 164,
backend-1 | severity: 'ERROR',
backend-1 | code: '22P02',
backend-1 | detail: undefined,
backend-1 | hint: undefined,
backend-1 | position: undefined,
backend-1 | internalPosition: undefined,
backend-1 | internalQuery: undefined,
backend-1 | where: "unnamed portal parameter $1 = '...'",
backend-1 | schema: undefined,
backend-1 | table: undefined,
backend-1 | column: undefined,
backend-1 | dataType: undefined,
backend-1 | constraint: undefined,
backend-1 | file: 'uuid.c',
backend-1 | line: '138',
backend-1 | routine: 'string_to_uuid'
backend-1 | }
backend-1 | # SERVER_ERROR: error: invalid input syntax for type uuid: "SjqCWRUKZhI31p8tA8GYBdZhtWf171x3"
backend-1 | at /app/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11
...
backend-1 | length: 164,
backend-1 | severity: 'ERROR',
backend-1 | code: '22P02',
backend-1 | detail: undefined,
backend-1 | hint: undefined,
backend-1 | position: undefined,
backend-1 | internalPosition: undefined,
backend-1 | internalQuery: undefined,
backend-1 | where: "unnamed portal parameter $1 = '...'",
backend-1 | schema: undefined,
backend-1 | table: undefined,
backend-1 | column: undefined,
backend-1 | dataType: undefined,
backend-1 | constraint: undefined,
backend-1 | file: 'uuid.c',
backend-1 | line: '138',
backend-1 | routine: 'string_to_uuid'
backend-1 | }
export const users = pgTable("users", {
id: uuid().primaryKey().defaultRandom(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified").notNull(),
image: text("image"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});

export const sessions = authSchema.table("sessions", {
id: uuid().primaryKey().defaultRandom(),
expiresAt: timestamp("expires_at").notNull(),
token: text("token").notNull().unique(),
createdAt: timestamp("created_at").notNull(),
updatedAt: timestamp("updated_at").notNull(),
ipAddress: text("ip_address"),
userAgent: text("user_agent"),
userId: uuid("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
});

export const accounts = authSchema.table("accounts", {
id: uuid().primaryKey().defaultRandom(),
accountId: text("account_id").notNull(),
providerId: text("provider_id").notNull(),
userId: uuid("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
accessToken: text("access_token"),
refreshToken: text("refresh_token"),
idToken: text("id_token"),
accessTokenExpiresAt: timestamp("access_token_expires_at"),
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
scope: text("scope"),
password: text("password"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});

export const verifications = authSchema.table("verifications", {
id: uuid().primaryKey().defaultRandom(),
identifier: text("identifier").notNull(),
value: text("value").notNull(),
expiresAt: timestamp("expires_at").notNull(),
createdAt: timestamp("created_at"),
updatedAt: timestamp("updated_at"),
});
export const users = pgTable("users", {
id: uuid().primaryKey().defaultRandom(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified").notNull(),
image: text("image"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});

export const sessions = authSchema.table("sessions", {
id: uuid().primaryKey().defaultRandom(),
expiresAt: timestamp("expires_at").notNull(),
token: text("token").notNull().unique(),
createdAt: timestamp("created_at").notNull(),
updatedAt: timestamp("updated_at").notNull(),
ipAddress: text("ip_address"),
userAgent: text("user_agent"),
userId: uuid("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
});

export const accounts = authSchema.table("accounts", {
id: uuid().primaryKey().defaultRandom(),
accountId: text("account_id").notNull(),
providerId: text("provider_id").notNull(),
userId: uuid("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
accessToken: text("access_token"),
refreshToken: text("refresh_token"),
idToken: text("id_token"),
accessTokenExpiresAt: timestamp("access_token_expires_at"),
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
scope: text("scope"),
password: text("password"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});

export const verifications = authSchema.table("verifications", {
id: uuid().primaryKey().defaultRandom(),
identifier: text("identifier").notNull(),
value: text("value").notNull(),
expiresAt: timestamp("expires_at").notNull(),
createdAt: timestamp("created_at"),
updatedAt: timestamp("updated_at"),
});
It is happening on signin, due to session getting its own ID instead of using the generated ID by the database better-auth 1.2.7

Did you find this page helpful?