[GH-ISSUE #7129] Prisma adapter doesn't catch P2025 errors on Prisma 7 - sign-out throws #10738

Closed
opened 2026-04-13 07:03:24 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @aniravi24 on GitHub (Jan 5, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7129

Description

Sign-out fails with a P2025 error when the session doesn't exist in the database. The Prisma adapter's error handling doesn't catch this on Prisma 7.

Environment

  • better-auth: 1.4.10
  • @prisma/client: 7.2.0
  • Node.js: 22.x

Error

Invalid `prisma.session.delete()` invocation:

An operation failed because it depends on one or more records that were required but not found.
No record was found for a delete.

{
  code: 'P2025',
  meta: { modelName: 'Session', operation: 'a delete' },
  clientVersion: '7.2.0'
}

Root Cause

In prisma-adapter.ts line 467, the delete method checks e?.meta?.cause but Prisma 7 no longer has a cause field in the error meta - it should check e?.code === 'P2025' instead.

Reproduction

This happens when a user has a stale session cookie (session was deleted from DB but cookie still exists) and tries to sign out.

Originally created by @aniravi24 on GitHub (Jan 5, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7129 ## Description Sign-out fails with a P2025 error when the session doesn't exist in the database. The Prisma adapter's error handling doesn't catch this on Prisma 7. ## Environment - better-auth: 1.4.10 - @prisma/client: 7.2.0 - Node.js: 22.x ## Error ``` Invalid `prisma.session.delete()` invocation: An operation failed because it depends on one or more records that were required but not found. No record was found for a delete. { code: 'P2025', meta: { modelName: 'Session', operation: 'a delete' }, clientVersion: '7.2.0' } ``` ## Root Cause In [`prisma-adapter.ts` line 467](https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts#L467), the delete method checks `e?.meta?.cause` but Prisma 7 no longer has a `cause` field in the error meta - it should check `e?.code === 'P2025'` instead. ## Reproduction This happens when a user has a stale session cookie (session was deleted from DB but cookie still exists) and tries to sign out.
GiteaMirror added the lockedbug labels 2026-04-13 07:03:24 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 5, 2026):

It looks like the Prisma adapter is encountering a P2025 error when trying to delete a session that doesn't exist in the database. As you've correctly identified, the error handling in the adapter needs to check for e?.code === 'P2025' instead of looking for the cause field, which is no longer present in Prisma 7's error meta.

Next Steps:

  1. Modify the Error Handling: Update the delete method in the Prisma adapter to catch P2025 errors directly. This involves changing the check in prisma-adapter.ts to look specifically for e.code === 'P2025'.

  2. Test the Changes: After making the changes, test the sign-out flow again with a stale session cookie to ensure that it handles the P2025 error gracefully.

  3. Create an Issue/PR: If you haven't done so already, consider opening an issue or a pull request to inform others about this enhancement.

You may want to tag @better-auth-agent for any additional inquiries or support needed from the team. Do you need guidance on how to implement these changes?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3709017680 --> @better-auth-agent[bot] commented on GitHub (Jan 5, 2026): It looks like the Prisma adapter is encountering a P2025 error when trying to delete a session that doesn't exist in the database. As you've correctly identified, the error handling in the adapter needs to check for `e?.code === 'P2025'` instead of looking for the `cause` field, which is no longer present in Prisma 7's error meta. ### Next Steps: 1. **Modify the Error Handling**: Update the delete method in the Prisma adapter to catch P2025 errors directly. This involves changing the check in `prisma-adapter.ts` to look specifically for `e.code === 'P2025'`. 2. **Test the Changes**: After making the changes, test the sign-out flow again with a stale session cookie to ensure that it handles the P2025 error gracefully. 3. **Create an Issue/PR**: If you haven't done so already, consider opening an issue or a pull request to inform others about this enhancement. You may want to tag @better-auth-agent for any additional inquiries or support needed from the team. Do you need guidance on how to implement these changes? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10738