[PR #637] [CLOSED] fix: should use deleteMany instead of delete on session table using token field #11656

Closed
opened 2026-04-13 07:55:29 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/637
Author: @pakenfit
Created: 11/23/2024
Status: Closed

Base: mainHead: fix/session-delete-error-on-signout


📝 Commits (1)

  • 92763fa fix: should deleteMany instead of delete on session table using token field

📊 Changes

1 file changed (+2 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/db/internal-adapter.ts (+2 -2)

📄 Description

In Prisma (probably others) when deleting session on user logout, we use delete with field token. Since this field is not id or unique field we should use deleteMany otherwise there is an error:

prisma:error 
Invalid `db[getModelName(model)].delete()` invocation in
better-auth/src/adapters/prisma-adapter/prisma-adapter.ts:237:41

  234 const { model, where } = data;
  235 const whereClause = convertWhereClause(model, where);
  236 try {
→ 237   await db[getModelName(model)].delete({
          where: {
            token: "YGx--5eI4P6trC6g3EQT27GjFmzPosMde",
        ?   id?: String,
        ?   AND?: SessionWhereInput | SessionWhereInput[],
        ?   OR?: SessionWhereInput[],
        ?   NOT?: SessionWhereInput | SessionWhereInput[],
        ?   expiresAt?: DateTimeFilter | DateTime,
        ?   ipAddress?: StringNullableFilter | String | Null,
        ?   userAgent?: StringNullableFilter | String | Null,
        ?   userId?: StringFilter | String,
        ?   createdAt?: DateTimeFilter | DateTime,
        ?   updatedAt?: DateTimeFilter | DateTime,
        ?   user?: UserRelationFilter | UserWhereInput
          }
        })

Argument `where` of type SessionWhereUniqueInput needs at least one of `id` arguments. Available options are marked with ?.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/637 **Author:** [@pakenfit](https://github.com/pakenfit) **Created:** 11/23/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/session-delete-error-on-signout` --- ### 📝 Commits (1) - [`92763fa`](https://github.com/better-auth/better-auth/commit/92763faac785dfc94eedef775d75bafc2d901bd0) fix: should deleteMany instead of delete on session table using token field ### 📊 Changes **1 file changed** (+2 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/internal-adapter.ts` (+2 -2) </details> ### 📄 Description In Prisma (probably others) when deleting `session` on user logout, we use `delete` with field `token`. Since this field is not `id` or `unique field` we should use `deleteMany` otherwise there is an error: ```` prisma:error Invalid `db[getModelName(model)].delete()` invocation in better-auth/src/adapters/prisma-adapter/prisma-adapter.ts:237:41 234 const { model, where } = data; 235 const whereClause = convertWhereClause(model, where); 236 try { → 237 await db[getModelName(model)].delete({ where: { token: "YGx--5eI4P6trC6g3EQT27GjFmzPosMde", ? id?: String, ? AND?: SessionWhereInput | SessionWhereInput[], ? OR?: SessionWhereInput[], ? NOT?: SessionWhereInput | SessionWhereInput[], ? expiresAt?: DateTimeFilter | DateTime, ? ipAddress?: StringNullableFilter | String | Null, ? userAgent?: StringNullableFilter | String | Null, ? userId?: StringFilter | String, ? createdAt?: DateTimeFilter | DateTime, ? updatedAt?: DateTimeFilter | DateTime, ? user?: UserRelationFilter | UserWhereInput } }) Argument `where` of type SessionWhereUniqueInput needs at least one of `id` arguments. Available options are marked with ?. ```` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 07:55:29 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#11656