Setting the deprecatedadvanced.generate option to false doesn't disable ID generation since version 1.2.6 #1043

Closed
opened 2026-03-13 08:20:14 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @honmanyau on GitHub (Apr 14, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Ensure that you are have better-auth version 1.2.7 installed.
  2. Create/alter the id column of the user table required by better-auth to have the UUID data type. Example Postgres schema:
    export const userTable = pgTable("user", {
    	id: uuid("id").defaultRandom().primaryKey(),
    	name: text("name").notNull(),
    	email: text("email").notNull().unique(),
    	emailVerified: boolean("email_verified").notNull(),
    	createdAt: timestamp("created_at").notNull(),
    	updatedAt: timestamp("updated_at").notNull(),    
    	image: text("image"),
    });
    
  3. In the better-auth config, set the deprecated advanced.generateId option to `false:
    export const auth = betterAuth({
        // ...
        advanced: {
            generateId: false,
        }
    });
    
  4. Create a user and observe an the error APIError: Failed to create user:
    await auth.api.signUpEmail({
        body: {
            ...generateUserData(),
            password,
        },
    });
    
  5. Observe that the underlying error is a PostgresError with details similar to PostgresError: invalid input syntax for type uuid: "MRaM1HgFyo99l6YHkVlNRBC5YumDmEtU". In this case it's because better-auth's default ID generation gives a format that isn't a UUID. Regardless, the issue is that better-auth shouldn't be generating an ID at all.
  6. Install version 1.2.5, create a user and observe that the error does not appear.
  7. Install version 1.2.6 or 1.2.7, and set the new advanced.database.generateId flag to false, create a user and observe that the error does not appear.

Current vs. Expected behavior

Current behaviour (version 1.2.7 at the time of writing, but also applies to 1.2.6):

  • Setting the advanced.generateId option to false does not disable ID generation.

Expected behaviour:

  • Setting the advanced.generateId option to false should disable ID generation.
  • Setting the advanced.generateId option to false should show a warning in the console that it's deprecated.

What version of Better Auth are you using?

1.2.7

Provide environment information

- OS: macOS Sequoia 15.4
- Runtime: Deno

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth";

export const auth = betterAuth({
    database: drizzleAdapter(db, {
        provider: "pg",
        schema: {
            user: userTable,
            session: sessionTable,
            account: accountTable,
            verification: verificationTable,
        },
    }),
    plugins: [
        customSession(async ({ user, session }) => {
            const roles = await userRoleService.getUserRoles(
                DANGEROUS_SYSTEM_USER,
                user.id,
            );

            return {
                user,
                session: {
                    ...session,
                    roles,
                },
            };
        }),
    ],
    advanced: {
        generateId: false, // <-- Where the issue is.
    },
    emailAndPassword: {
        enabled: Deno.env.get("ENVIRONMENT") === "development",
    },
    socialProviders,
});

Additional context

I have only looked at the code so far but I think the issue is in the newly introduced file, packages/better-auth/src/adapters/create-adapter/index.ts, where we have this check:

if (options.advanced?.generateId) {
	logger.warn(
		"Your Better Auth config includes advanced.generateId which is deprecated. Please use advanced.database.generateId instead. This will be removed in future releases.",
	);
	generateId = options.advanced?.generateId;
}

Which doesn't account for the case where advanced.generateId is false. I think it should be a check for whether or the the value is defined instead, which will also set generateId in the outer scope to false correctly so that it can be evaluated in the statement when we explicitly check whether or not generate === false:

if (options.advanced?.generateId !== undefined) {
	logger.warn(
		"Your Better Auth config includes advanced.generateId which is deprecated. Please use advanced.database.generateId instead. This will be removed in future releases.",
	);
	generateId = options.advanced?.generateId;
}

Applying that patch does fix the issue for me.

I'm more than happy to submit a PR for this if that's indeed the expected behaviour and if needed. :)

Originally created by @honmanyau on GitHub (Apr 14, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Ensure that you are have `better-auth` version 1.2.7 installed. 2. Create/alter the `id` column of the `user` table required by `better-auth` to have the UUID data type. Example Postgres schema: ```ts export const userTable = pgTable("user", { id: uuid("id").defaultRandom().primaryKey(), name: text("name").notNull(), email: text("email").notNull().unique(), emailVerified: boolean("email_verified").notNull(), createdAt: timestamp("created_at").notNull(), updatedAt: timestamp("updated_at").notNull(), image: text("image"), }); ``` 2. In the `better-auth` config, set the deprecated `advanced.generateId` option to `false: ```ts export const auth = betterAuth({ // ... advanced: { generateId: false, } }); ``` 3. Create a user and observe an the error `APIError: Failed to create user`: ```ts await auth.api.signUpEmail({ body: { ...generateUserData(), password, }, }); ``` 4. Observe that the underlying error is a `PostgresError` with `details` similar to ` PostgresError: invalid input syntax for type uuid: "MRaM1HgFyo99l6YHkVlNRBC5YumDmEtU"`. In this case it's because `better-auth`'s default ID generation gives a format that isn't a UUID. Regardless, the issue is that `better-auth` shouldn't be generating an ID at all. 5. Install version 1.2.5, create a user and observe that the error does not appear. 6. Install version 1.2.6 or 1.2.7, and set the new `advanced.database.generateId` flag to `false`, create a user and observe that the error does not appear. ### Current vs. Expected behavior Current behaviour (version 1.2.7 at the time of writing, but also applies to 1.2.6): - Setting the `advanced.generateId` option to `false` does not disable ID generation. Expected behaviour: - Setting the `advanced.generateId` option to `false` should disable ID generation. - Setting the `advanced.generateId` option to `false` should show a warning in the console that it's deprecated. ### What version of Better Auth are you using? 1.2.7 ### Provide environment information ```bash - OS: macOS Sequoia 15.4 - Runtime: Deno ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", schema: { user: userTable, session: sessionTable, account: accountTable, verification: verificationTable, }, }), plugins: [ customSession(async ({ user, session }) => { const roles = await userRoleService.getUserRoles( DANGEROUS_SYSTEM_USER, user.id, ); return { user, session: { ...session, roles, }, }; }), ], advanced: { generateId: false, // <-- Where the issue is. }, emailAndPassword: { enabled: Deno.env.get("ENVIRONMENT") === "development", }, socialProviders, }); ``` ### Additional context I have only looked at the code so far but I think the issue is in the newly introduced file, [packages/better-auth/src/adapters/create-adapter/index.ts](https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/adapters/create-adapter/index.ts), where we have this check: ```ts if (options.advanced?.generateId) { logger.warn( "Your Better Auth config includes advanced.generateId which is deprecated. Please use advanced.database.generateId instead. This will be removed in future releases.", ); generateId = options.advanced?.generateId; } ``` Which doesn't account for the case where `advanced.generateId` is `false`. I think it should be a check for whether or the the value is defined instead, which will also set `generateId` in the outer scope to `false` correctly so that it can be evaluated in the statement when we explicitly check whether or not `generate === false`: ```ts if (options.advanced?.generateId !== undefined) { logger.warn( "Your Better Auth config includes advanced.generateId which is deprecated. Please use advanced.database.generateId instead. This will be removed in future releases.", ); generateId = options.advanced?.generateId; } ``` Applying that patch does fix the issue for me. I'm more than happy to submit a PR for this if that's indeed the expected behaviour and if needed. :)
Author
Owner

@Kinfe123 commented on GitHub (Apr 19, 2025):

it is already fixed

@Kinfe123 commented on GitHub (Apr 19, 2025): it is already fixed
Author
Owner

@honmanyau commented on GitHub (Apr 19, 2025):

it is already fixed

Thank you! ☀️🎉

@honmanyau commented on GitHub (Apr 19, 2025): > it is already fixed Thank you! ☀️🎉
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1043