Throwing Error when try to login with existing user
export const auth = betterAuth({
database: drizzleAdapter(drizzleDb, {
provider: "sqlite",
}),
socialProviders: {
google: {
clientId: process.env.AUTH_GOOGLE_CLIENT_ID! as string,
clientSecret: process.env.AUTH_GOOGLE_CLIENT_SECRET! as string,
},
},
user:{
additionalFields:{
credits:{
type: "number",
default: 350,
},
subscriptionTier: {
type: "string",
default: "free",
},
subscriptionStartDate: {
type: "date",
},
subscriptionEndDate: {
type: "date",
},
lastCreditPurchase: {
type: "date",
},
totalCreditsUsed: {
type: "number",
default: 0,
},
stripeCustomerId: {
type: "string",
},
stripeSubscriptionId: {
type: "string",
},
stripePriceId: {
type: "string",
},
stripeCurrentPeriodEnd: {
type: "date",
},
}
}
});
export const user = sqliteTable("user", {
id: text("id").primaryKey().notNull(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
emailVerified: integer("email_verified", { mode: "boolean" }).notNull(),
image: text("image"),
credits: integer().default(350).notNull(),
subscriptionTier: text().default("free").notNull(),
subscriptionStartDate: integer({ mode: "timestamp" }),
subscriptionEndDate: integer({ mode: "timestamp" }),
lastCreditPurchase: numeric(),
totalCreditsUsed: integer({ mode: "number" }).default(0),
stripeCustomerId: text("stripe_customer_id"),
stripeSubscriptionId: text("stripe_subscription_id"),
stripePriceId: text("stripe_price_id"),
stripeCurrentPeriodEnd: numeric("stripe_current_period_end"),
createdAt: integer("created_at", { mode: "timestamp" }).notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull(),
});

17 Replies
What version are you on?
"better-auth": "^1.2.5",
Macos
i update to 1.2.7 still getting the error

In the drizzleAdapter function, can you pass the
debugLog
option and set to true?Query: insert into "verification" ("id", "identifier", "value", "expires_at", "created_at", "updated_at") values (?, ?, ?, ?, ?, ?) returning "id", "identifier", "value", "expires_at", "created_at", "updated_at" -- params: ["fpKKsqIVVt2gxdzpyvuU2NZkziGsq3q5", "0Q8x-pDIIX-wDsfg5PaHuq3kdllOVD5T", "{\"callbackURL\":\"/dashboard\",\"codeVerifier\":\"9IPkC6r4IdPaHSGjDycjTtFfgFtFoVFVMBhfkls3yvOf8NmYHswnuHi17GxM6YO_SIki-u7zXXkpeuddnnsFHJo97tT1G-BTj-oEz8ln1K4kefOfXK4oMTsb\",\"errorURL\":\"/sign-in\",\"expiresAt\":1744827950742}", 1744827950, 1744827350, 1744827350]
Query: select "id", "identifier", "value", "expires_at", "created_at", "updated_at" from "verification" where "verification"."identifier" = ? order by "verification"."created_at" desc limit ? -- params: ["0Q8x-pDIIX-wDsfg5PaHuq3kdllOVD5T", 1]
Query: delete from "verification" where "verification"."expires_at" < ? -- params: [1744827353]
Query: delete from "verification" where "verification"."id" = ? -- params: ["fpKKsqIVVt2gx62uhggNZkziGsq3q5"]
Query: select "id", "account_id", "provider_id", "user_id", "access_token", "refresh_token", "id_token", "access_token_expires_at", "refresh_token_expires_at", "scope", "password", "created_at", "updated_at" from "account" where ("account"."account_id" = ? and "account"."provider_id" = ?) -- params: ["1885100000009536", "google"]
Query: select "id", "name", "email", "email_verified", "image", "credits", "subscriptionTier", "subscriptionStartDate", "subscriptionEndDate", "lastCreditPurchase", "totalCreditsUsed", "stripe_customer_id", "stripe_subscription_id", "stripe_price_id", "stripe_current_period_end", "created_at", "updated_at" from "user" where "user"."id" = ? -- params: ["oYiFGWTA2ArOVRchO6bYc58sFbcv1Vmd"]
Query: insert into "user" ("id", "name", "email", "email_verified", "image", "credits", "subscriptionTier", "subscriptionStartDate", "subscriptionEndDate", "lastCreditPurchase", "totalCreditsUsed", "stripe_customer_id", "stripe_subscription_id", "stripe_price_id", "stripe_current_period_end", "created_at", "updated_at") values (?, ?, ?, ?, ?, ?, ?, null, null, null, ?, null, null, null, null, ?, ?) returning "id", "name", "email", "email_verified", "image", "credits", "subscriptionTier", "subscriptionStartDate", "subscriptionEndDate", "lastCreditPurchase", "totalCreditsUsed", "stripe_customer_id", "stripe_subscription_id", "stripe_price_id", "stripe_current_period_end", "created_at", "updated_at" -- params: ["N8970Qc5mmQbK2OKuEme7FXVQ0vvKIwb", "My name", "[email protected]", 1, "https://lh3.googleusercontent.com/a/12345677yKKbb2n665QV=s96-c", 350, "free", 0, 1744827354, 1744827354]
2025-04-16T18:15:54.884Z ERROR [Better Auth]: LibsqlError: SQLITE_CONSTRAINT: SQLite error: UNIQUE constraint failed: user.email
2025-04-16T18:15:54.885Z ERROR [Better Auth]: unable_to_create_user
GET /api/auth/callback/google?state=0Q8x-pDIIX-wDsfg5PaHugfffdhlOVD5T&code=4%2F0Ab_5qlm05xdUOhLBxPT24628PpxCpborBiO6RvvHnI63r7QDkda15iuybhlkGk63gWw&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&authuser=0&prompt=none 302 in 2112ms
these are the logs after i click the buttonCan you put these in proper codeblocks in discord? It's hard to read.
@Ping updated
That... doesn't look like normal debug logs from Better auth adapters
Can you show me your auth config again?
Okay yeah, do you see your
drizzleAdapter
code? In there, next to your provider
, please add debugLogs: true
@Ping this is all the log

You never explained that you were linking accounts, not basic login š
Quite crucial information š
i just add it now to check not using that feature
i think i fixed the issue i need to truncate the account table also
i was following the migration guide from Next auth
i only truncate the user table but never thought about the account table
Solution
i think adding a small note in the migration guide might be useful
Migrating from NextAuth.js to Better Auth | Better Auth
A step-by-step guide to transitioning from NextAuth.js to Better Auth.
@Ping thank you bro
š«°šæ