Better AuthBA
Better Auth11mo ago
8 replies
King Alastor

Better-auth cannot be set up using pg Pool and postgres

It seems somewhere in the code there's hardcoded user relation when trying to set up:
database: new Pool({
connectionString: process.env.DATABASE_URL,
}),
tables: {
user: "users",
account: "account",
session: "session",
verification: "verification"
},

re-mapping has no effect, you still get an error:
2025-02-27T20:29:35.974Z ERROR [Better Auth]: Better auth was unable to query your database.
Error:  [error: relation "user" does not exist] {
  length: 103,
  severity: 'ERROR',
  code: '42P01',
  detail: undefined,
  hint: undefined,
  position: '15',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'parse_relation.c',
  line: '1452',
  routine: 'parserOpenTable'
}
 GET /api/auth/callback/google?state=MAMMsYQKDb35w4C1JT8jGjqf6NXPecCy&code=4%2F0AQSTgQF4TIZX_veUgaUBV0f5hQ_AkYIuNYRfKKQkeM49kg1oUnAozryq-X5hlGjCawOePg&scope=email+profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+openid&authuser=0&prompt=none 302 in 557ms
 GET /api/auth/error?error=internal_server_error 200 in 68ms

When you use the npx @better-auth/cli generate command, it generates a migration file with "user" table and "user" relations but you cannot create a user table in postgres, it's reserved word. But when trying to log in, it still looks for the user table, dismissing the remapping to "users" table in auth.ts

user: {
modelName: "users",

this gives me error:
2025-02-27T21:22:31.581Z ERROR [Better Auth]: unable_to_create_user
Was this page helpful?