Error with custom field mapping. whereClause id getting undefined value

I'm migrating from Auth0 to better-auth.

In my existing project users table called UsersView (don't ask). And the primary key is userId (instead of just
id
)

Here is my config:
export const auth = betterAuth({
  user: {
    modelName: 'UsersView',
    fields: {
      name: 'firstName',
      id: 'userId',
      email: 'email',
      image: 'avatarUrl',
    },
  },
  session: {
    modelName: 'auth_sessions',
  },
  account: {
    modelName: 'auth_account',
  },
  verification: {
    modelName: 'auth_verification',
  },
  database: prismaAdapter(prisma, {
    provider: 'mysql',
  }),
  plugins: [
    emailOTP({
      async sendVerificationOTP({ email, otp, type }) {
        if (type === 'sign-in') {
          console.log(email, otp);
        }
        // Implement the sendVerificationOTP method to send the OTP to the user's email address //
      },
    }),
  ],
  trustedOrigins: ['***'],
});


The OTP code is generating succesfuly:
And here is the db record that I'm getting in verifications table: (see screenshot)


Now when I submit the code I'm getting an error
# SERVER_ERROR:  PrismaClientValidationError:
Invalid `db[getModelName(model)].update()` invocation in
/Users/ilyalibin/Dev/thrive-be/node_modules/better-auth/dist/adapters/prisma-adapter/index.mjs:217:52

Argument `where` of type UsersViewWhereUniqueInput needs at least one of `userId` arguments. Available options are marked with


When I console log the whereClause, here is what I see.
ANY /hono/api/auth/sign-in/email-otp (λ: honoApp)
whereClause { id: undefined }
data {
  model: 'user',
  update: { emailVerified: true },
  where: [ { field: 'id', value: undefined } ]
}
where [ { field: 'id', value: undefined } ]



Please advice
image.png
Was this page helpful?