1

I'm setting up my nuxt project and I want to configure better-auth to use my companies Oauth2/OIDC provider to authenticate against with the genericOauth plugin. When running npx @better-auth/cli@latest generate --config ./server/utils/auth.ts the database gets created in the right place, but it's empty and no schema is generated (see error message below -> no tables found).

Any idea what's wrong with my setup? Thank you and BR Simon

This is my server/utils/auth.ts:

import { betterAuth } from "better-auth"
import { genericOAuth } from "better-auth/plugins"
import Database from "better-sqlite3"

export const auth = betterAuth({
  database: {
    provider: "sqlite",  // This tells Better Auth it's SQLite
    type: "sqlite",      // Add this line to be explicit
    db: new Database("server/database/auth/local.db")
  },
  plugins: [
    genericOAuth({
      config: [
        {
          providerId: "sso",
          clientId: process.env["NUXT_OAUTH_SSO_CLIENT_ID"] || '',
          clientSecret: process.env["NUXT_OAUTH_SSO_CLIENT_SECRET"] || '',
          discoveryUrl: process.env["NUXT_OAUTH_SSO_CONFIGURATION_URL"] || '',
        },
      ]
    })
  ]
})

And this is the output I get:

npx @better-auth/cli@latest generate --config ./server/utils/auth.ts
⠋ preparing schema...file:///Users/taasasi8/.npm/_npx/05eee8cc65087e98/node_modules/better-auth/dist/shared/better-auth.D-L3RQ6y.mjs:1143
  const tableMetadata = await db.introspection.getTables();
                                               ^

TypeError: Cannot read properties of undefined (reading 'getTables')
    at getMigrations (file:///Users/taasasi8/.npm/_npx/05eee8cc65087e98/node_modules/better-auth/dist/shared/better-auth.D-L3RQ6y.mjs:1143:48)
    at async generateMigrations (file:///Users/taasasi8/.npm/_npx/05eee8cc65087e98/node_modules/@better-auth/cli/dist/index.mjs:2660:33)
    at async Command.generateAction (file:///Users/taasasi8/.npm/_npx/05eee8cc65087e98/node_modules/@better-auth/cli/dist/index.mjs:2720:18)

1 Answer 1

0

The problem is how you set the database... Right way:

import { betterAuth } from 'better-auth';
import { genericOAuth } from 'better-auth/plugins';
import Database from 'better-sqlite3';

export const auth = betterAuth({
  database: new Database('./local.db'),
  plugins: [
    genericOAuth({
      config: [
        {
          providerId: 'sso',
          clientId: process.env['NUXT_OAUTH_SSO_CLIENT_ID'] || '',
          clientSecret: process.env['NUXT_OAUTH_SSO_CLIENT_SECRET'] || '',
          discoveryUrl: process.env['NUXT_OAUTH_SSO_CONFIGURATION_URL'] || '',
        },
      ],
    }),
  ],
});

This works: 2025-11-13T12:03:20.127Z SUCCESS [Better Auth]: 🚀 Schema was generated successfully!

More infos here: https://www.better-auth.com/docs/installation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.