[BUG] Admin Plugin - Setting ban duration to undefined doesn't clear the ban_expires column #689

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

Originally created by @danielfr9 on GitHub (Feb 17, 2025).

Originally assigned to: @Kinfe123 on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Configure the admin plugin.
  2. Create a user.
  3. Ban the user with a defined duration (e.g., 2 minutes for testing).
  4. Unban the user.
  5. Ban the user without specifying a duration (banExpiresIn as undefined).
  6. Wait until the previous ban's expiration time has passed.
  7. Attempt to sign in as the banned user.
  8. The user is able to sign in despite being "permanently" banned.

Current vs. Expected behavior

Currently, banning a user without a specified duration sets the banned column to TRUE but retains the previous ban_expires value. As a result, when the user tries to sign in, the system checks the previous expiration date to determine access. If the previous ban has expired, the user is allowed to sign in, even though they were intended to be permanently banned.

To prevent this, ban_expires should be cleared when banning a user without a duration or during the unbanning process.

What version of Better Auth are you using?

1.1.18

Provide environment information

- OS: Windows 11
- Browser: Zen Browser 1.7.6b
- Runtime: Node.js v20.18.0

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

Backend, Client

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg", 
  }),
  emailAndPassword: {  
    enabled: true
  },
  plugins: [
    username(),
    admin(),
    nextCookies(),
  ],
});

Additional context

Image

According to the docs, if the expiration is not defined, then the ban is permanent

Originally created by @danielfr9 on GitHub (Feb 17, 2025). Originally assigned to: @Kinfe123 on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Configure the admin plugin. 2. Create a user. 3. Ban the user with a defined duration (e.g., 2 minutes for testing). 4. Unban the user. 5. Ban the user without specifying a duration (banExpiresIn as undefined). 6. Wait until the previous ban's expiration time has passed. 7. Attempt to sign in as the banned user. 8. The user is able to sign in despite being "permanently" banned. ### Current vs. Expected behavior Currently, banning a user without a specified duration sets the banned column to TRUE but retains the previous ban_expires value. As a result, when the user tries to sign in, the system checks the previous expiration date to determine access. If the previous ban has expired, the user is allowed to sign in, even though they were intended to be permanently banned. To prevent this, ban_expires should be cleared when banning a user without a duration or during the unbanning process. ### What version of Better Auth are you using? 1.1.18 ### Provide environment information ```bash - OS: Windows 11 - Browser: Zen Browser 1.7.6b - Runtime: Node.js v20.18.0 ``` ### Which area(s) are affected? (Select all that apply) Backend, Client ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", }), emailAndPassword: { enabled: true }, plugins: [ username(), admin(), nextCookies(), ], }); ``` ### Additional context ![Image](https://github.com/user-attachments/assets/fce42d76-e97d-4320-88be-a64771f53a75) According to the docs, if the expiration is not defined, then the ban is permanent
GiteaMirror added the bug label 2026-03-13 08:00:28 -05:00
Author
Owner

@TariqueAnowar commented on GitHub (Feb 17, 2025):

Image

i am also facing same issue.

@TariqueAnowar commented on GitHub (Feb 17, 2025): ![Image](https://github.com/user-attachments/assets/108d6a2c-83ea-4d07-b01d-128ad81b181e) i am also facing same issue.
Author
Owner

@Kinfe123 commented on GitHub (Feb 17, 2025):

@TariqueAnowar this is already a pr for that .... expect the fix soon

@Kinfe123 commented on GitHub (Feb 17, 2025): @TariqueAnowar this is already a pr for that .... expect the fix soon
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#689