[GH-ISSUE #1629] API Key Plugin: Error while deleting api key #8843

Closed
opened 2026-04-13 04:04:52 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @opswiz on GitHub (Mar 2, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1629

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Use api key plugin to delete the api key with prisma postgress.

While calling

 await auth.api.deleteApiKey({
      body: {
        keyId: id,
      },
      headers: await headers(),
    });
Argument `lt`: Invalid value provided. Expected DateTime or DateTimeFieldRefInput, provided Int.] {
  clientVersion: '6.4.1'
}
 ⨯ unhandledRejection:  [Error [PrismaClientValidationError]:
Invalid `db[getModelName(model)].deleteMany()` invocation in
/Users/opswiz/Developer/app/.next/server/chunks/ssr/node_modules_better-auth_dist_58a41214._.js:2884:62

  2881 async deleteMany (data) {
  2882     const { model, where } = data;
  2883     const whereClause = convertWhereClause(model, where);
→ 2884     const result = await db[getModelName(model)].deleteMany({
             where: {
               expiresAt: {
                 lt: 1740908359196
                     ~~~~~~~~~~~~~
               }
             }
           })

Argument `lt`: Invalid value provided. Expected DateTime or DateTimeFieldRefInput, provided Int.] {
  clientVersion: '6.4.1'
}

Current vs. Expected behavior

expected, The delete should work by providing the key

What version of Better Auth are you using?

1.2.0

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:23:36 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T8112
  Available memory (MB): 8192
  Available CPU cores: 8
Binaries:
  Node: 22.14.0
  npm: 11.1.0
  Yarn: N/A
  pnpm: 10.5.2
Relevant Packages:
  next: 15.2.0 // Latest available version is detected (15.2.0).
  eslint-config-next: 15.2.0
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
import { apiKey } from 'better-auth/plugins';

export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
  plugins: [
    apiKey()
  ]
});

Additional context

No response

Originally created by @opswiz on GitHub (Mar 2, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1629 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Use api key plugin to delete the api key with prisma postgress. While calling ```ts await auth.api.deleteApiKey({ body: { keyId: id, }, headers: await headers(), }); ``` ``` Argument `lt`: Invalid value provided. Expected DateTime or DateTimeFieldRefInput, provided Int.] { clientVersion: '6.4.1' } ⨯ unhandledRejection: [Error [PrismaClientValidationError]: Invalid `db[getModelName(model)].deleteMany()` invocation in /Users/opswiz/Developer/app/.next/server/chunks/ssr/node_modules_better-auth_dist_58a41214._.js:2884:62 2881 async deleteMany (data) { 2882 const { model, where } = data; 2883 const whereClause = convertWhereClause(model, where); → 2884 const result = await db[getModelName(model)].deleteMany({ where: { expiresAt: { lt: 1740908359196 ~~~~~~~~~~~~~ } } }) Argument `lt`: Invalid value provided. Expected DateTime or DateTimeFieldRefInput, provided Int.] { clientVersion: '6.4.1' } ``` ### Current vs. Expected behavior expected, The delete should work by providing the key ### What version of Better Auth are you using? 1.2.0 ### Provide environment information ```bash Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:23:36 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T8112 Available memory (MB): 8192 Available CPU cores: 8 Binaries: Node: 22.14.0 npm: 11.1.0 Yarn: N/A pnpm: 10.5.2 Relevant Packages: next: 15.2.0 // Latest available version is detected (15.2.0). eslint-config-next: 15.2.0 react: 19.0.0 react-dom: 19.0.0 typescript: 5.7.3 Next.js Config: output: N/A ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" import { apiKey } from 'better-auth/plugins'; export const auth = betterAuth({ emailAndPassword: { enabled: true }, plugins: [ apiKey() ] }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 04:04:53 -05:00
Author
Owner

@opswiz commented on GitHub (Mar 2, 2025):

@Bekacru . just looking around why deleteApiKey is not working. was debugging through the installed code

await ctx.context.adapter.delete({
  model: schema.apikey.modelName,
  where: [
    {
      field: "id",
      value: apiKey.id,
    },
    {
      field: "userId", // works if this clause removed
      value: session.user.id,
    },
  ],
});

if I comment the userId where clause things are working. but with both id and userId its not working. simply no error and does nothing as well. any thoughts?

<!-- gh-comment-id:2692799023 --> @opswiz commented on GitHub (Mar 2, 2025): @Bekacru . just looking around why deleteApiKey is not working. was debugging through the installed code ```ts await ctx.context.adapter.delete({ model: schema.apikey.modelName, where: [ { field: "id", value: apiKey.id, }, { field: "userId", // works if this clause removed value: session.user.id, }, ], }); ``` if I comment the userId where clause things are working. but with both id and userId its not working. simply no error and does nothing as well. any thoughts?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8843