Regression when calling deleteUser #1358

Closed
opened 2026-03-13 08:34:46 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @madflow on GitHub (Jun 15, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  session: {
    freshAge: 60 * 5,
  },
  1. install v1.2.8 and deleteUser with a fresh session.
  • Deletion works
  1. install v1.2.9 and deleteUser with a fresh session.
{
  "code": "SESSION_EXPIRED_REAUTHENTICATE_TO_PERFORM_THIS_ACTION",
  "message": "Session expired. Re-authenticate to perform this action."
} 

Set freshAge to a high value.

  session: {
    freshAge: 60 * 5000,
  },
  • Deletion works.

  • The problem could be different timezones (or missing handling of the timezones).

Current vs. Expected behavior

  • I would expect either a documented way how to do handle different timezones or "better" handling of timezone differences (if this is even the culprit here).

What version of Better Auth are you using?

v1.2.9

Provide environment information

- Next.Js 15
- Drizzle Adapter
- Postgres 17

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

Backend

Auth config (if applicable)


Additional context

services:

  # https://hub.docker.com/_/postgres/
  postgres:
    image: "postgres:17-alpine"
    command: "postgres -c log_statement=all"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
      start_period: 20s
      interval: 30s
      retries: 5
      timeout: 5s
    environment:
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
      - POSTGRES_USER=${POSTGRES_USER:-postgres}
      - POSTGRES_DB=${POSTGRES_DB:-postgres}
    ports:
      - "5432:5432"
export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
    usePlural: true,
    schema,
  }),
  user: {
    deleteUser: {
      enabled: true,
    },
  },
  emailAndPassword: {
    enabled: true,
  },
});
"use client";

import { authClient } from "@/lib/auth-client";

function handleDeleteUser() {
  authClient.deleteUser().catch(console.error);
}
export function DeleteUser() {
  return <button onClick={handleDeleteUser}>Delete user</button>;
}
Originally created by @madflow on GitHub (Jun 15, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ``` session: { freshAge: 60 * 5, }, ``` 1. install v1.2.8 and `deleteUser` with a fresh session. - Deletion works 2. install v1.2.9 and `deleteUser` with a fresh session. ``` { "code": "SESSION_EXPIRED_REAUTHENTICATE_TO_PERFORM_THIS_ACTION", "message": "Session expired. Re-authenticate to perform this action." } ``` Set freshAge to a high value. ``` session: { freshAge: 60 * 5000, }, ``` - Deletion works. - The problem could be different timezones (or missing handling of the timezones). ### Current vs. Expected behavior - I would expect either a documented way how to do handle different timezones or "better" handling of timezone differences (if this is even the culprit here). ### What version of Better Auth are you using? v1.2.9 ### Provide environment information ```bash - Next.Js 15 - Drizzle Adapter - Postgres 17 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context - I also tested this with this Starter: https://github.com/daveyplate/better-auth-nextjs-starter, and I get the same result: ``` services: # https://hub.docker.com/_/postgres/ postgres: image: "postgres:17-alpine" command: "postgres -c log_statement=all" healthcheck: test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"] start_period: 20s interval: 30s retries: 5 timeout: 5s environment: - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres} - POSTGRES_USER=${POSTGRES_USER:-postgres} - POSTGRES_DB=${POSTGRES_DB:-postgres} ports: - "5432:5432" ``` ``` export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", usePlural: true, schema, }), user: { deleteUser: { enabled: true, }, }, emailAndPassword: { enabled: true, }, }); ``` ``` "use client"; import { authClient } from "@/lib/auth-client"; function handleDeleteUser() { authClient.deleteUser().catch(console.error); } export function DeleteUser() { return <button onClick={handleDeleteUser}>Delete user</button>; } ```
GiteaMirror added the nextjsbug labels 2026-03-13 08:34:46 -05:00
Author
Owner

@xiaoyu2er commented on GitHub (Jun 22, 2025):

Q: if this is related to fresh session, why not use SESSION_IS_NOT_FRESH (authClient.unlinkAccount throws this error) instead?

@xiaoyu2er commented on GitHub (Jun 22, 2025): Q: if this is related to fresh session, why not use `SESSION_IS_NOT_FRESH` (`authClient.unlinkAccount` throws this error) instead?
Author
Owner

@dosubot[bot] commented on GitHub (Sep 21, 2025):

Hi, @madflow. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported a regression in Better Auth v1.2.9 where deleteUser fails on a fresh session with a SESSION_EXPIRED_REAUTHENTICATE_TO_PERFORM_THIS_ACTION error.
  • This behavior differs from v1.2.8, where the error did not occur under the same conditions.
  • The issue seems related to session freshness and possibly timezone handling, as increasing freshAge reduces the problem.
  • The maintainer noted confusion about why the error isn't the expected SESSION_IS_NOT_FRESH.
  • You requested better documentation or handling regarding timezone effects on session expiration.

Next Steps:

  • Please confirm if this issue still occurs with the latest version of better-auth and if it remains relevant to your use case.
  • If so, you can keep the discussion open by commenting on this issue; otherwise, I will automatically close it in 7 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Sep 21, 2025): Hi, @madflow. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported a regression in Better Auth v1.2.9 where `deleteUser` fails on a fresh session with a `SESSION_EXPIRED_REAUTHENTICATE_TO_PERFORM_THIS_ACTION` error. - This behavior differs from v1.2.8, where the error did not occur under the same conditions. - The issue seems related to session freshness and possibly timezone handling, as increasing `freshAge` reduces the problem. - The maintainer noted confusion about why the error isn't the expected `SESSION_IS_NOT_FRESH`. - You requested better documentation or handling regarding timezone effects on session expiration. **Next Steps:** - Please confirm if this issue still occurs with the latest version of better-auth and if it remains relevant to your use case. - If so, you can keep the discussion open by commenting on this issue; otherwise, I will automatically close it in 7 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1358