auth.api.getSession returning null despite passing in headers

Unclear if I'm missing something or if I'm running into a bug, I was hoping someone could help out. We're working on moving from AuthJS to Better Auth with a NextJS application. We do not have a database and will be using a stateless approach.

I started out with a POC rather than introducing it into our application, so I'm running into this with a fresh install of Next 15 + Better Auth 1.4.7
When I call auth.api.getSesssion in a server action, it returns null once the session_data cookie is expired. But, if I call "get-session" via the API using fetch it uses the session_token cookie and still returns the session. I am unclear if I'm doing something wrong, if this is intended behavior, or if I'm hitting into a bug?

My server action looks like this:
export const getSession = async () => {
    const headersCopy = await headers();
    for (const [key, value] of headersCopy.entries()) {
        console.log(`${key}: ${value}`); // verify that cookies are in header
    }
    const session = await auth.api.getSession({
        headers: headersCopy,
    });

    return session;
}
Was this page helpful?