authClient.listSessions returns empty array #903

Closed
opened 2026-03-13 08:09:13 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @hammeradam on GitHub (Mar 23, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Project Stack:

  • hono
  • better-auth
  • postgres

When calling either authClient.listSessions or auth.api.listSessions it always returns an empty array even tho the sessions are persisted in the database and are not expired.

Current vs. Expected behavior

Current: Empty array is returned
Expected: Users active sessions are returned

What version of Better Auth are you using?

1.2.4

Provide environment information

- os: macos 15.3.2
- browser: chrome 134.0.6998.89

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

Backend, Client

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

I probably have the solution, needed the issue opened to open a pr for it.

Originally created by @hammeradam on GitHub (Mar 23, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Project Stack: - hono - better-auth - postgres When calling either `authClient.listSessions` or `auth.api.listSessions` it always returns an empty array even tho the sessions are persisted in the database and are not expired. ### Current vs. Expected behavior Current: Empty array is returned Expected: Users active sessions are returned ### What version of Better Auth are you using? 1.2.4 ### Provide environment information ```bash - os: macos 15.3.2 - browser: chrome 134.0.6998.89 ``` ### 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({ emailAndPassword: { enabled: true }, }); ``` ### Additional context I probably have the solution, needed the issue opened to open a pr for it.
GiteaMirror added the bug label 2026-03-13 08:09:13 -05:00
Author
Owner

@moshetanzer commented on GitHub (Mar 23, 2025):

Hey,

I don't have this issue. What does your auth client look like?

@moshetanzer commented on GitHub (Mar 23, 2025): Hey, I don't have this issue. What does your auth client look like?
Author
Owner

@hammeradam commented on GitHub (Mar 23, 2025):

Hey @moshetanzer,

this is the client:

import { createAuthClient } from 'better-auth/react';

export const authClient = createAuthClient({
  baseURL: import.meta.env.VITE_API_BASE_URL,
});

Can you take a look at the PR I created?
I think it makes sense and it fixes the issue for me.
Can it be database dependent maybe?

@hammeradam commented on GitHub (Mar 23, 2025): Hey @moshetanzer, this is the client: ``` import { createAuthClient } from 'better-auth/react'; export const authClient = createAuthClient({ baseURL: import.meta.env.VITE_API_BASE_URL, }); ``` Can you take a look at the PR I created? I think it makes sense and it fixes the issue for me. Can it be database dependent maybe?
Author
Owner

@hammeradam commented on GitHub (Mar 23, 2025):

Looking at it now, according to the typescript types expiresAt should be a Date but actually it is a string in runtime.

@hammeradam commented on GitHub (Mar 23, 2025): Looking at it now, according to the typescript types expiresAt should be a Date but actually it is a string in runtime.
Author
Owner

@hammeradam commented on GitHub (Mar 23, 2025):

I think I found the problem, it was on me.
I'm using the drizzle adapter, and I had the session as:
expiresAt: timestamp({ mode: 'string' }).notNull()

I changed it to:
expiresAt: timestamp({ mode: 'date' }).notNull()

It fixed it. Should I close the issue and PR?

@hammeradam commented on GitHub (Mar 23, 2025): I think I found the problem, it was on me. I'm using the drizzle adapter, and I had the session as: `expiresAt: timestamp({ mode: 'string' }).notNull()` I changed it to: `expiresAt: timestamp({ mode: 'date' }).notNull()` It fixed it. Should I close the issue and PR?
Author
Owner

@moshetanzer commented on GitHub (Mar 23, 2025):

Hey @hammeradam,

Yip! Thanks for your investigations thought ❤

@moshetanzer commented on GitHub (Mar 23, 2025): Hey @hammeradam, Yip! Thanks for your investigations thought ❤
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#903