[GH-ISSUE #1035] ERROR: unable_to_create_user #17191

Closed
opened 2026-04-15 15:12:44 -05:00 by GiteaMirror · 23 comments
Owner

Originally created by @eliasdanielr on GitHub (Dec 27, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1035

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create a mono repo with [Turborepo](https://turbo.build/repo/docs).
  2. Create packages/database using Drizzle ORM. Here are its schemas.
  3. Create packages/auth. Here are the auth, authClient, and Next.js handlers.
  4. Create apps/web using Next.js 15.1.0.
  5. Use authClient.signIn.social with any provider.
  6. See ERROR [Better Auth]: unable_to_create_user in the console.

Current vs. Expected behavior

When I sign in with a social provider, the user is not created as expected. At first, I looked up other related issues and found #1025, but in my case, it’s not an issue with my database schema. To be more sure, before deleting the .next folder, I also removed the birthDay plugin to see if it was an issue with my implementation. The error doesn’t provide enough information to figure out what’s going wrong. I tried the basics: making sure my database server is running, manually creating a user using Drizzle ORM, and even deleting the .next folder (I was getting desperate).

What version of Better Auth are you using?

1.1.4

Provide environment information

- Framework: Next.js
- Database adapter: Drizzle
- Database: postgres
- OS: Linux Ubuntu x86_64

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@g3deon/database";
import { envConfig } from "../config";
import { twoFactor } from "better-auth/plugins";
import { username } from "better-auth/plugins";
import z from "zod";
import { nextCookies } from "better-auth/next-js";
import { birthdayPlugin } from "./plugins/birthday";
import {
  users,
  accounts,
  sessions,
  verifications,
} from "@g3deon/database/schemas";

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
    schema: { users, accounts, sessions, verifications },
    usePlural: true,
  }),
  emailAndPassword: {
    enabled: true,
  },
  user: {
    additionalFields: {
      accentColor: {
        type: "number",
        required: false,
        defaultValue: 0,
      },
      locale: {
        type: "string",
        required: false,
        defaultValue: "en-US",
      },
    },
    fields: {
      name: "display_name",
    },
  },
  socialProviders: {
    google: {
      enabled: true,
      clientId: envConfig.GOOGLE_CLIENT_ID,
      clientSecret: envConfig.GOOGLE_CLIENT_SECRET,
    },
    github: {
      enabled: true,
      clientId: envConfig.GITHUB_CLIENT_ID,
      clientSecret: envConfig.GITHUB_CLIENT_SECRET,
    },
    discord: {
      enabled: true,
      clientId: envConfig.DISCORD_CLIENT_ID,
      clientSecret: envConfig.DISCORD_CLIENT_SECRET,
    },
  },
  plugins: [twoFactor(), username(), nextCookies(), birthdayPlugin()],
});

// src/auth-client.ts

import { usernameClient } from "better-auth/client/plugins";
import { twoFactorClient } from "better-auth/plugins";
import { createAuthClient } from "better-auth/react";
import { birthdayClientPlugin } from "./plugins/birthday";

export const authClient = createAuthClient({
	plugins: [
		usernameClient(),
		twoFactorClient({
			onTwoFactorRedirect() {
				window.location.href = "/2fa";
			},
		}),
		birthdayClientPlugin(),
	],
});

Additional context

This was tested without any users pre-created in the database. The expectation is that users should be automatically created when using a social provider.

Originally created by @eliasdanielr on GitHub (Dec 27, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1035 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. **Create a mono repo with [[Turborepo](https://turbo.build/repo/docs)](https://turbo.build/repo/docs).** 2. **Create `packages/database` using Drizzle ORM.** Here are its schemas. 3. **Create `packages/auth`.** Here are the auth, authClient, and Next.js handlers. 4. **Create `apps/web` using Next.js 15.1.0.** 5. **Use `authClient.signIn.social` with any provider.** 6. **See ERROR [Better Auth]: unable_to_create_user in the console.** ### Current vs. Expected behavior When I sign in with a social provider, the user is not created as expected. At first, I looked up other related issues and found #1025, but in my case, **it’s not an issue with my database schema.** To be more sure, before deleting the .next folder, I also removed the birthDay plugin to see if it was an issue with my implementation. The error doesn’t provide enough information to figure out what’s going wrong. **I tried the basics**: making sure my database server is running, manually creating a user using Drizzle ORM, and even deleting the .next folder (I was getting desperate). ### What version of Better Auth are you using? 1.1.4 ### Provide environment information ```bash - Framework: Next.js - Database adapter: Drizzle - Database: postgres - OS: Linux Ubuntu x86_64 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "@g3deon/database"; import { envConfig } from "../config"; import { twoFactor } from "better-auth/plugins"; import { username } from "better-auth/plugins"; import z from "zod"; import { nextCookies } from "better-auth/next-js"; import { birthdayPlugin } from "./plugins/birthday"; import { users, accounts, sessions, verifications, } from "@g3deon/database/schemas"; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", schema: { users, accounts, sessions, verifications }, usePlural: true, }), emailAndPassword: { enabled: true, }, user: { additionalFields: { accentColor: { type: "number", required: false, defaultValue: 0, }, locale: { type: "string", required: false, defaultValue: "en-US", }, }, fields: { name: "display_name", }, }, socialProviders: { google: { enabled: true, clientId: envConfig.GOOGLE_CLIENT_ID, clientSecret: envConfig.GOOGLE_CLIENT_SECRET, }, github: { enabled: true, clientId: envConfig.GITHUB_CLIENT_ID, clientSecret: envConfig.GITHUB_CLIENT_SECRET, }, discord: { enabled: true, clientId: envConfig.DISCORD_CLIENT_ID, clientSecret: envConfig.DISCORD_CLIENT_SECRET, }, }, plugins: [twoFactor(), username(), nextCookies(), birthdayPlugin()], }); // src/auth-client.ts import { usernameClient } from "better-auth/client/plugins"; import { twoFactorClient } from "better-auth/plugins"; import { createAuthClient } from "better-auth/react"; import { birthdayClientPlugin } from "./plugins/birthday"; export const authClient = createAuthClient({ plugins: [ usernameClient(), twoFactorClient({ onTwoFactorRedirect() { window.location.href = "/2fa"; }, }), birthdayClientPlugin(), ], }); ``` ### Additional context This was tested without any users pre-created in the database. The expectation is that users should be automatically created when using a social provider.
GiteaMirror added the lockedbug labels 2026-04-15 15:12:44 -05:00
Author
Owner

@Bekacru commented on GitHub (Dec 27, 2024):

my guess is you have mapped name to display_name incorrectly. if the key in the schema object is something like this displayName: text("display_name") you should map name to displayName in the field config. The adapter only have the drizzle object context.

<!-- gh-comment-id:2563361597 --> @Bekacru commented on GitHub (Dec 27, 2024): my guess is you have mapped `name` to `display_name` incorrectly. if the key in the schema object is something like this `displayName: text("display_name")` you should map `name` to `displayName` in the field config. The adapter only have the drizzle object context.
Author
Owner

@eliasdanielr commented on GitHub (Dec 27, 2024):

Anyway, I used @better-auth/cli generate to create the schema, but I deleted it and tried again, and I get the same error message.

<!-- gh-comment-id:2563969901 --> @eliasdanielr commented on GitHub (Dec 27, 2024): Anyway, I used @better-auth/cli generate to create the schema, but I deleted it and tried again, and I get the same error message.
Author
Owner

@Bekacru commented on GitHub (Dec 27, 2024):

if you generated the schema remove the field configuration

<!-- gh-comment-id:2563979409 --> @Bekacru commented on GitHub (Dec 27, 2024): if you generated the schema remove the field configuration
Author
Owner

@eliasdanielr commented on GitHub (Dec 27, 2024):

Are you referring to the displayName? I already removed it and tested that, I also removed the additionalFields, and it's still the same error.

<!-- gh-comment-id:2563980797 --> @eliasdanielr commented on GitHub (Dec 27, 2024): Are you referring to the `displayName`? I already removed it and tested that, I also removed the `additionalFields`, and it's still the same error.
Author
Owner

@eliasdanielr commented on GitHub (Dec 28, 2024):

Update: I tried doing the regular sign-up, using authClient.signUp.email() and got a different error message:

Failed to create user TypeError: value.toISOString is not a function
    at Array.map (<anonymous>)
    at Array.map (<anonymous>)
    at Array.map (<anonymous>)

Here’s a bit more context:

// auth.ts
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@g3deon/database";
import { envConfig } from "../config";
import { twoFactor } from "better-auth/plugins";
import { username } from "better-auth/plugins";
import z from "zod";
import { nextCookies } from "better-auth/next-js";
import {
	users,
	accounts,
	sessions,
	verifications,
} from "@g3deon/database/schemas";

export const auth = betterAuth({
	database: drizzleAdapter(db, {
		provider: "pg",
		schema: { users, accounts, sessions, verifications },
		usePlural: true,
	}),
	emailAndPassword: {
		enabled: true,
	},
	user: {
		additionalFields: {
			accentColor: {
				type: "number",
				required: false,
				defaultValue: 0,
			},
			birthday: {
				type: "date",
				required: false,
				defaultValue: null,
			},
			locale: {
				type: "string",
				required: false,
				defaultValue: "en-US",
			},
		},
	},
	socialProviders: {
		google: {
			enabled: true,
			clientId: envConfig.GOOGLE_CLIENT_ID,
			clientSecret: envConfig.GOOGLE_CLIENT_SECRET,
		},
		github: {
			enabled: true,
			clientId: envConfig.GITHUB_CLIENT_ID,
			clientSecret: envConfig.GITHUB_CLIENT_SECRET,
		},
		discord: {
			enabled: true,
			clientId: envConfig.DISCORD_CLIENT_ID,
			clientSecret: envConfig.DISCORD_CLIENT_SECRET,
		},
	},
	plugins: [twoFactor(), username(), nextCookies()],
});

// auth.client.ts

import { inferAdditionalFields, usernameClient } from "better-auth/client/plugins";
import { twoFactorClient } from "better-auth/plugins";
import { createAuthClient } from "better-auth/react";
import type { auth } from "./auth";

export const authClient = createAuthClient({
	plugins: [
		usernameClient(),
		twoFactorClient({
			onTwoFactorRedirect() {
				window.location.href = "/2fa";
			},
		}),
		inferAdditionalFields<typeof auth>(),
	],
});
// schemas.ts

import {
	pgTable,
	text,
	integer,
	timestamp,
	boolean,
} from "drizzle-orm/pg-core";

export const users = pgTable("users", {
	id: text("id").primaryKey(),
	name: text("name").notNull(),
	email: text("email").notNull().unique(),
	emailVerified: boolean("email_verified").notNull(),
	image: text("image"),
	createdAt: timestamp("created_at").notNull(),
	updatedAt: timestamp("updated_at").notNull(),
	twoFactorEnabled: boolean("two_factor_enabled"),
	username: text("username").unique(),
	birthday: timestamp("birthday").notNull(),
	accentColor: integer("accent_color"),
	locale: text("locale"),
});

export const sessions = pgTable("sessions", {
	id: text("id").primaryKey(),
	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: text("user_id")
		.notNull()
		.references(() => users.id),
});

export const accounts = pgTable("accounts", {
	id: text("id").primaryKey(),
	accountId: text("account_id").notNull(),
	providerId: text("provider_id").notNull(),
	userId: text("user_id")
		.notNull()
		.references(() => users.id),
	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(),
	updatedAt: timestamp("updated_at").notNull(),
});

export const verifications = pgTable("verifications", {
	id: text("id").primaryKey(),
	identifier: text("identifier").notNull(),
	value: text("value").notNull(),
	expiresAt: timestamp("expires_at").notNull(),
	createdAt: timestamp("created_at"),
	updatedAt: timestamp("updated_at"),
});

export const twoFactors = pgTable("two_factors", {
	id: text("id").primaryKey(),
	secret: text("secret").notNull(),
	backupCodes: text("backup_codes").notNull(),
	userId: text("user_id")
		.notNull()
		.references(() => users.id),
});
<!-- gh-comment-id:2564417699 --> @eliasdanielr commented on GitHub (Dec 28, 2024): Update: I tried doing the regular sign-up, using `authClient.signUp.email()` and got a different error message: ``` Failed to create user TypeError: value.toISOString is not a function at Array.map (<anonymous>) at Array.map (<anonymous>) at Array.map (<anonymous>) ``` Here’s a bit more context: ```ts // auth.ts import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "@g3deon/database"; import { envConfig } from "../config"; import { twoFactor } from "better-auth/plugins"; import { username } from "better-auth/plugins"; import z from "zod"; import { nextCookies } from "better-auth/next-js"; import { users, accounts, sessions, verifications, } from "@g3deon/database/schemas"; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", schema: { users, accounts, sessions, verifications }, usePlural: true, }), emailAndPassword: { enabled: true, }, user: { additionalFields: { accentColor: { type: "number", required: false, defaultValue: 0, }, birthday: { type: "date", required: false, defaultValue: null, }, locale: { type: "string", required: false, defaultValue: "en-US", }, }, }, socialProviders: { google: { enabled: true, clientId: envConfig.GOOGLE_CLIENT_ID, clientSecret: envConfig.GOOGLE_CLIENT_SECRET, }, github: { enabled: true, clientId: envConfig.GITHUB_CLIENT_ID, clientSecret: envConfig.GITHUB_CLIENT_SECRET, }, discord: { enabled: true, clientId: envConfig.DISCORD_CLIENT_ID, clientSecret: envConfig.DISCORD_CLIENT_SECRET, }, }, plugins: [twoFactor(), username(), nextCookies()], }); ``` ```ts // auth.client.ts import { inferAdditionalFields, usernameClient } from "better-auth/client/plugins"; import { twoFactorClient } from "better-auth/plugins"; import { createAuthClient } from "better-auth/react"; import type { auth } from "./auth"; export const authClient = createAuthClient({ plugins: [ usernameClient(), twoFactorClient({ onTwoFactorRedirect() { window.location.href = "/2fa"; }, }), inferAdditionalFields<typeof auth>(), ], }); ``` ```ts // schemas.ts import { pgTable, text, integer, timestamp, boolean, } from "drizzle-orm/pg-core"; export const users = pgTable("users", { id: text("id").primaryKey(), name: text("name").notNull(), email: text("email").notNull().unique(), emailVerified: boolean("email_verified").notNull(), image: text("image"), createdAt: timestamp("created_at").notNull(), updatedAt: timestamp("updated_at").notNull(), twoFactorEnabled: boolean("two_factor_enabled"), username: text("username").unique(), birthday: timestamp("birthday").notNull(), accentColor: integer("accent_color"), locale: text("locale"), }); export const sessions = pgTable("sessions", { id: text("id").primaryKey(), 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: text("user_id") .notNull() .references(() => users.id), }); export const accounts = pgTable("accounts", { id: text("id").primaryKey(), accountId: text("account_id").notNull(), providerId: text("provider_id").notNull(), userId: text("user_id") .notNull() .references(() => users.id), 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(), updatedAt: timestamp("updated_at").notNull(), }); export const verifications = pgTable("verifications", { id: text("id").primaryKey(), identifier: text("identifier").notNull(), value: text("value").notNull(), expiresAt: timestamp("expires_at").notNull(), createdAt: timestamp("created_at"), updatedAt: timestamp("updated_at"), }); export const twoFactors = pgTable("two_factors", { id: text("id").primaryKey(), secret: text("secret").notNull(), backupCodes: text("backup_codes").notNull(), userId: text("user_id") .notNull() .references(() => users.id), }); ```
Author
Owner

@eliasdanielr commented on GitHub (Dec 28, 2024):

It seems that there is a problem when putting the birthday with the date type, I remove it and got the expected result.

<!-- gh-comment-id:2564519396 --> @eliasdanielr commented on GitHub (Dec 28, 2024): It seems that there is a problem when putting the `birthday` with the `date` type, I remove it and got the expected result.
Author
Owner

@Afulton11 commented on GitHub (Jan 3, 2025):

Update: I tried doing the regular sign-up, using authClient.signUp.email() and got a different error message:

I noticed this same error message when I accidentally updated the existing session using one of the expiresAt/updatedAt/createdAt fields. For me, this occurs because the dates retrieved from the database (using drizzle & auth.api.getSession()) are resolved to strings and not Dates.

@eliasdanielr So a fix for your case would be to explicitly construct a Date object for the birthday string.

<!-- gh-comment-id:2568657309 --> @Afulton11 commented on GitHub (Jan 3, 2025): > Update: I tried doing the regular sign-up, using `authClient.signUp.email()` and got a different error message: I noticed this same error message when I _accidentally_ updated the existing session using one of the `expiresAt`/`updatedAt`/`createdAt` fields. For me, this occurs because the dates retrieved from the database (using drizzle & `auth.api.getSession()`) are resolved to strings and not Dates. @eliasdanielr So a fix for your case would be to explicitly construct a Date object for the birthday string.
Author
Owner

@eliasdanielr commented on GitHub (Jan 7, 2025):

Finally, it worked! This should be documented.

<!-- gh-comment-id:2574299455 --> @eliasdanielr commented on GitHub (Jan 7, 2025): Finally, it worked! This should be documented.
Author
Owner

@carere commented on GitHub (Feb 19, 2025):

@Afulton11 Hello, I have the same problem with a fresh install of Better Auth.
I'm using email / password authentication & Google auth.
I have this error when trying to create a user with google. The problems comes from timestamp fields.
What should I do to solve this problem ?

<!-- gh-comment-id:2669313663 --> @carere commented on GitHub (Feb 19, 2025): @Afulton11 Hello, I have the same problem with a fresh install of Better Auth. I'm using email / password authentication & Google auth. I have this error when trying to create a user with google. The problems comes from timestamp fields. What should I do to solve this problem ?
Author
Owner

@richardamare commented on GitHub (Feb 19, 2025):

I'm experiencing the same issue with timestamps with Google auth as @carere.

ERROR [Better Auth]: TypeError: value.toISOString is not a function
<!-- gh-comment-id:2669916436 --> @richardamare commented on GitHub (Feb 19, 2025): I'm experiencing the same issue with timestamps with Google auth as @carere. ``` ERROR [Better Auth]: TypeError: value.toISOString is not a function ```
Author
Owner

@benjamindell commented on GitHub (Feb 24, 2025):

I am also experiencing this issue (when resetting a password). Can someone advise what we need to do in order to parse date fields from a string to a date object? Not quite sure where we do that in the Drizzle config??

<!-- gh-comment-id:2678175924 --> @benjamindell commented on GitHub (Feb 24, 2025): I am also experiencing this issue (when resetting a password). Can someone advise what we need to do in order to parse date fields from a string to a date object? Not quite sure where we do that in the Drizzle config??
Author
Owner

@richardamare commented on GitHub (Feb 24, 2025):

I managed to generate the db schema using https://www.better-auth.com/docs/concepts/database#generating-schema (npx @better-auth/cli generate) and then add my own tables. It worked out of the box afterwards. Hope this helps 🙏

@carere @benjamindell

<!-- gh-comment-id:2678468732 --> @richardamare commented on GitHub (Feb 24, 2025): I managed to generate the db schema using https://www.better-auth.com/docs/concepts/database#generating-schema (`npx @better-auth/cli generate`) and then add my own tables. It worked out of the box afterwards. Hope this helps 🙏 @carere @benjamindell
Author
Owner

@benjamindell commented on GitHub (Feb 24, 2025):

Thanks @richardamare - Are you using Drizzle for your ORM / DB provider?

<!-- gh-comment-id:2678502336 --> @benjamindell commented on GitHub (Feb 24, 2025): Thanks @richardamare - Are you using Drizzle for your ORM / DB provider?
Author
Owner

@benjamindell commented on GitHub (Feb 24, 2025):

Any chance you can share your scheme for the user / account tables? @richardamare

<!-- gh-comment-id:2678506221 --> @benjamindell commented on GitHub (Feb 24, 2025): Any chance you can share your scheme for the user / account tables? @richardamare
Author
Owner

@focux commented on GitHub (Feb 24, 2025):

Seems that this bug was introduced recently, I upgraded from ^1.1.14 to 1.2.0-beta.15 and started getting this issue when sign in with Google.

<!-- gh-comment-id:2678890703 --> @focux commented on GitHub (Feb 24, 2025): Seems that this bug was introduced recently, I upgraded from `^1.1.14` to `1.2.0-beta.15` and started getting this issue when sign in with Google.
Author
Owner

@benjamindell commented on GitHub (Feb 24, 2025):

Ah @focux - yes i also recently upgraded to the 1.2 beta. Hopefully the team are aware of it and working on a fix.

<!-- gh-comment-id:2679005219 --> @benjamindell commented on GitHub (Feb 24, 2025): Ah @focux - yes i also recently upgraded to the 1.2 beta. Hopefully the team are aware of it and working on a fix.
Author
Owner

@focux commented on GitHub (Feb 24, 2025):

Yeah, just opened a PR here to fix this issue.

<!-- gh-comment-id:2679042427 --> @focux commented on GitHub (Feb 24, 2025): Yeah, just opened a PR [here](https://github.com/better-auth/better-auth/pull/1563) to fix this issue.
Author
Owner

@danteyc commented on GitHub (Feb 24, 2025):

I am also experiencing this issue, I try to log in with google (with a user already registered previously), in my case I use mongoDbAdapter. I have version 1.1.19, I downgraded to 1.1.18 and so on until 1.1.14 and I still have the same error.

<!-- gh-comment-id:2679056116 --> @danteyc commented on GitHub (Feb 24, 2025): I am also experiencing this issue, I try to log in with google (with a user already registered previously), in my case I use mongoDbAdapter. I have version 1.1.19, I downgraded to 1.1.18 and so on until 1.1.14 and I still have the same error.
Author
Owner

@AsenCME commented on GitHub (Apr 1, 2025):

Don't know why this is closed as the issue clearly still persist. For me:

  • mongodb adapter (mongodb 6.15.0)
  • better-auth 1.2.5

When a user, that already has a google account, tries to log in again, it says "unable_to_create_user". I do not understand why it tries to create a user right away.

<!-- gh-comment-id:2770243808 --> @AsenCME commented on GitHub (Apr 1, 2025): Don't know why this is closed as the issue clearly still persist. For me: - mongodb adapter (mongodb 6.15.0) - better-auth 1.2.5 When a user, that already has a google account, tries to log in again, it says "unable_to_create_user". I do not understand why it tries to create a user right away.
Author
Owner

@zf0x00 commented on GitHub (Apr 16, 2025):

do not understand why it tries to create a user right away.

i also have the same issue any fixes ?

<!-- gh-comment-id:2808428426 --> @zf0x00 commented on GitHub (Apr 16, 2025): > do not understand why it tries to create a user right away. i also have the same issue any fixes ?
Author
Owner

@Whats-A-MattR commented on GitHub (Apr 24, 2025):

Just had and resolved this issue.
I don't know which of the following was causing it. I had an extra column on the users table for a billing id, and had been truncating the user table to test hooks.
I changed to a linking table, regenerated my schemas with the CLI, generated a migration with drizzle, dropped all tables, ran the migration.

Now works fine.

<!-- gh-comment-id:2826344338 --> @Whats-A-MattR commented on GitHub (Apr 24, 2025): Just had and resolved this issue. I don't know which of the following was causing it. I had an extra column on the users table for a billing id, and had been truncating the user table to test hooks. I changed to a linking table, regenerated my schemas with the CLI, generated a migration with drizzle, dropped all tables, ran the migration. Now works fine.
Author
Owner

@Vic-Orlands commented on GitHub (Jul 16, 2025):

Don't know why this is closed as the issue clearly still persist. For me:

  • mongodb adapter (mongodb 6.15.0)
  • better-auth 1.2.5

When a user, that already has a google account, tries to log in again, it says "unable_to_create_user". I do not understand why it tries to create a user right away.

In my case, I was trying to pass user's google data as part of the data object in prisma.user.create() but the fields were not existing. Better-auth handles the creation but the fields need to added to your db User schema.

I added the missing fields to my User schema, and did a fresh migration. This solved my problem

<!-- gh-comment-id:3078272032 --> @Vic-Orlands commented on GitHub (Jul 16, 2025): > Don't know why this is closed as the issue clearly still persist. For me: > > * mongodb adapter (mongodb 6.15.0) > * better-auth 1.2.5 > > When a user, that already has a google account, tries to log in again, it says "unable_to_create_user". I do not understand why it tries to create a user right away. In my case, I was trying to pass user's google data as part of the data object in `prisma.user.create()` but the fields were not existing. Better-auth handles the creation but the fields need to added to your db User schema. I added the missing fields to my User schema, and did a fresh migration. This solved my problem
Author
Owner

@govindpvenu commented on GitHub (Oct 16, 2025):

For me i fogot to add this.

github: {
      clientId: "YOUR_GITHUB_CLIENT_ID",
      clientSecret: "YOUR_GITHUB_CLIENT_SECRET",
      mapProfileToUser: (profile) => {
        return {
          firstName: profile.name.split(" ")[0],
          lastName: profile.name.split(" ")[1],
        };
      },
},

See : https://www.better-auth.com/docs/concepts/database#extending-core-schema

<!-- gh-comment-id:3410052030 --> @govindpvenu commented on GitHub (Oct 16, 2025): For me i fogot to add this. ``` github: { clientId: "YOUR_GITHUB_CLIENT_ID", clientSecret: "YOUR_GITHUB_CLIENT_SECRET", mapProfileToUser: (profile) => { return { firstName: profile.name.split(" ")[0], lastName: profile.name.split(" ")[1], }; }, }, ``` See : https://www.better-auth.com/docs/concepts/database#extending-core-schema
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17191