Weird behavior when rememberMe is false.

When logging in with rememberMe: false, the session cookie is created and stored correctly (verified in browser + DB), but /v1/session (or /api/auth/get-session) returns null. With rememberMe: true, everything works fine. Both od the endpoints returns the session. What i've tried: Cookies are correctly set (better-auth.session_token, dont_remember) and sent with credentials: "include". Headers forwarded correctly in /v1/login, including Set-Cookie. Tried removing secure, no change. Session exists in the DB. When visiting /v1/session, still getting null. I'm using Next.js as the frontend and the Hono as separate backend where better auth is running. Here's the login route:
import { Hono } from "hono";
import { auth } from "../../lib/auth";

const loginRoute = new Hono();

loginRoute.post("/", async (c) => {
const { email, password, rememberMe } = await c.req.json();

const { headers, response } = await auth.api.signInEmail({
body: { email, password, rememberMe },
returnHeaders: true,
});


// parse and set cookies
headers.forEach((value, name) => {
if (name.toLowerCase() === "set-cookie") {
c.header("Set-Cookie", value);
}
});

return c.json(response);
});

export default loginRoute;
import { Hono } from "hono";
import { auth } from "../../lib/auth";

const loginRoute = new Hono();

loginRoute.post("/", async (c) => {
const { email, password, rememberMe } = await c.req.json();

const { headers, response } = await auth.api.signInEmail({
body: { email, password, rememberMe },
returnHeaders: true,
});


// parse and set cookies
headers.forEach((value, name) => {
if (name.toLowerCase() === "set-cookie") {
c.header("Set-Cookie", value);
}
});

return c.json(response);
});

export default loginRoute;
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?