allandelmare
allandelmare
BABetter Auth
Created by Sebastian on 4/16/2025 in #help
Using custom schema for models, with prisma adapter.
after fighting with this all day, I gave up and just gave my better auth instance its own database/connection string, now everything is operating smooth, clean, and easy. Best practice in most cases too, to give the Auth its own database me thinks ... speration of concerns and all that. The custom schema was more headache than it was worth
9 replies
BABetter Auth
Created by Sebastian on 4/16/2025 in #help
Using custom schema for models, with prisma adapter.
No description
9 replies
BABetter Auth
Created by Sebastian on 4/16/2025 in #help
Using custom schema for models, with prisma adapter.
No description
9 replies
BABetter Auth
Created by Sebastian on 4/16/2025 in #help
Using custom schema for models, with prisma adapter.
// 1. Setup PostgreSQL connection with schema management import { betterAuth } from 'better-auth'; import { createAuthMiddleware } from 'better-auth/api'; import pg from 'pg'; const { Pool } = pg; // Create database connection pool const pool = new Pool({ connectionString: process.env.DATABASE_URI || '', }); // Configure connection to use better_auth schema pool.on('connect', async (client) => { // Create schema if it doesn't exist await client.query('CREATE SCHEMA IF NOT EXISTS better_auth'); // Set search path to prefer better_auth schema await client.query('SET search_path TO better_auth'); }); // 2. Configure Better Auth with the pool export const auth = betterAuth({ // Basic configuration...
// Database configuration using PostgreSQL with better_auth schema database: pool,
// Simple user configuration with additional fields user: { additionalFields: { firstName: { type: "string", required: false }, lastName: { type: "string", required: false } } },
// Other configuration... }); // 3. Migration // Run the Better Auth CLI with: // npx @better-auth/cli@latest generate --config path/to/auth.ts // npx @better-auth/cli@latest migrate --config path/to/auth.ts
9 replies
BABetter Auth
Created by Sebastian on 4/16/2025 in #help
Using custom schema for models, with prisma adapter.
got it working with direct pg
9 replies
BABetter Auth
Created by Sebastian on 4/16/2025 in #help
Using custom schema for models, with prisma adapter.
I've gotten it 'working' with a hacky work-around and I want to find a better way: // In auth.ts export const auth = betterAuth({ // Other config...
// Explicitly prefix tables with schema user: { modelName: "better_auth.better_auth_user", // Note the schema prefix // ...fields config }, session: { modelName: "better_auth.better_auth_session", // ...fields config }, account: { modelName: "better_auth.better_auth_account", // ...fields config }, verification: { modelName: "better_auth.better_auth_verification", // ...fields config } });
9 replies
BABetter Auth
Created by Sebastian on 4/16/2025 in #help
Using custom schema for models, with prisma adapter.
need to know the same thing myself!
9 replies