Error when using Custom Tables

I am using Better Auth with NodeJS express written in Typescript. It works with default tables but when i customised the fields i get Cannot read properties of undefined (reading 'findFirst') error.

auth.ts
import { betterAuth } from 'better-auth';
import { prismaAdapter } from 'better-auth/adapters/prisma';

import { PrismaClientInstance } from './prisma';

export const auth = betterAuth({
    user: {
        modelName: 'users',
        fields: {
            email: 'email_address',
            emailVerified: 'email_verified',
            image: 'profile_picture',
            createdAt: 'created_at',
            updatedAt: 'updated_at'
        },
        additionalFields: {
            role: {
                type: 'string',
                required: true,
                defaultValue: 'user',
                input: false
            }
        }
    },
    session: {
        modelName: 'sessions',
        fields: {
            userId: 'user_id',
            expiresAt: 'expires_at',
            ipAddress: 'ip_address',
            userAgent: 'user_agent'
        }
    },
    account: {
        modelName: 'accounts',
        fields: {
            userId: 'user_id',
            accountId: 'account_id',
            providerId: 'provider_id',
            accessToken: 'access_token',
            refreshToken: 'refresh_token',
            expiresAt: 'expires_at'
        }
    },
    verification: {
        modelName: 'verifications',
        fields: {
            expiresAt: 'expires_at'
        }
    },
    database: prismaAdapter(PrismaClientInstance.getInstance(), {
        provider: 'postgresql',
    }),
    emailAndPassword: {
        enabled: true,
        requireEmailVerification: true
    },
});
Was this page helpful?