Facing a weird intermittent issue that's blocking our signups

Using "better-auth": "^1.2.9"/Next.js and Postgres. Have GitHub/Google Signups. When user is new on platform and tries to sign it, it says the error given in the photo. But when you go back. close tab, again open app, refresh and signup, then it signin without any issue. The api logs says:
2025-07-07T10:32:18.570Z ERROR [Better Auth]: error: relation "account" does not exist
2025-07-07T10:32:18.570Z ERROR [Better Auth]: unable_to_create_user
2025-07-07T10:32:18.570Z ERROR [Better Auth]: error: relation "account" does not exist
2025-07-07T10:32:18.570Z ERROR [Better Auth]: unable_to_create_user
But the thing is all the tables are present. and fact that its sometimes signing in without any issue. means this is not a table issue. Can anyone help with this? the webapp is here https://chaitea.chat - if you want to check it. Only happens when user is new
No description
3 Replies
Ping
Ping3mo ago
Can you share me your auth config?
nikatune
nikatune3mo ago
yeah can you send auth.ts
raj.js
raj.jsOP3mo ago
@Ping @nikatune i think i just found out. it was something to do with postgres table schema not being picked right by betterauth as i am having tables in different schema which is not public. i was setting it in pg file itself which was causing some race conditions. have done some changes of hardcoding schema searchpath on db side, its working now i think. checking with few new signups and see if i see that issue again, i'll notify. can you signup and see if you are getting that issue? i think its should be working now. i did that change in db itself as there is no way to specify schema of tables to be used in betterauth. it would be a great help if we can get a property to specify what schema under which postgres tables are present, as by default it picks public schema only. auth.ts
import { betterAuth } from "better-auth";
import pool from "./pg";
import { initializeNewUser } from "./user-init";

export const auth = betterAuth({
database: pool,
socialProviders: {
github: {
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
},
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
},
},
databaseHooks: {
user: {
create: {
after: async (user) => {

try {
await initializeNewUser({
user_id: user.id,
email: user.email,
});
} catch (error) {
console.error("Failed to initialize new user:", error);
}
},
},
},
},
});
import { betterAuth } from "better-auth";
import pool from "./pg";
import { initializeNewUser } from "./user-init";

export const auth = betterAuth({
database: pool,
socialProviders: {
github: {
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
},
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
},
},
databaseHooks: {
user: {
create: {
after: async (user) => {

try {
await initializeNewUser({
user_id: user.id,
email: user.email,
});
} catch (error) {
console.error("Failed to initialize new user:", error);
}
},
},
},
},
});

Did you find this page helpful?