Wrong session duration after impersonating #1006

Closed
opened 2026-03-13 08:17:10 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @MarcMogdanz on GitHub (Apr 8, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Log in as an admin, at this point the session cookie will have an expire date equal to the configured session duration
  2. Impersonate another user, this will write the current session to the admin_session helper cookie which also then has the expire date equal to the configured session duration and the actual session_token will expire at the end of the browser session
  3. Stop impersonating, the session_token value will be replaced by the admin_token again, but the cookie expire date will still be end of browser session

Current vs. Expected behavior

After stopping to impersonate the session_token cookie should either have it's original expire date restored or set to the default configured session duration, but not end of the browser session

What version of Better Auth are you using?

1.2.5

Provide environment information

-

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
import { admin } from 'better-auth/plugins'
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
  plugins: [admin()]
});

Additional context

No response

Originally created by @MarcMogdanz on GitHub (Apr 8, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Log in as an admin, at this point the session cookie will have an expire date equal to the configured session duration 2. Impersonate another user, this will write the current session to the `admin_session` helper cookie which also then has the expire date equal to the configured session duration and the actual `session_token` will expire at the end of the browser session 3. Stop impersonating, the `session_token` value will be replaced by the `admin_token` again, but the cookie expire date will still be end of browser session ### Current vs. Expected behavior After stopping to impersonate the `session_token` cookie should either have it's original expire date restored or set to the default configured session duration, but not end of the browser session ### What version of Better Auth are you using? 1.2.5 ### Provide environment information ```bash - ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" import { admin } from 'better-auth/plugins' export const auth = betterAuth({ emailAndPassword: { enabled: true }, plugins: [admin()] }); ``` ### Additional context _No response_
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1006