mark
mark
BABetter Auth
Created by ChowderCrab on 2/18/2025 in #help
Cookie cache does not refresh with server-side getSession call
I use the same way to refresh cache in v1.1.21. But I find it not working any more in v1.2.4. The ctx.setCookie is not called in v1.2.4
34 replies
BABetter Auth
Created by Dmitry on 3/1/2025 in #help
Cached Session Cookie (JWT) is not refreshed (SvelteKit)
This my middleware in express. It can refresh the cache cookie when it expired.
export const sessionMW = async (
req: Request,
res: Response,
next: Function
) => {
const ctx = {
headers: fromNodeHeaders(req.headers),
setCookie: (name: string, data: string, options: any) => {
console.log(`Setting cookie: ${name}`);
res.cookie(name, data, {
...options,
maxAge: config.sessionCache_maxAge * 1000, // 5 minutes
});
},
};
const session = await auth.api.getSession(ctx);

if (!session) {
return res.status(401).json({ error: "Unauthorized: Invalid session" });
}

req.session = session;
next();
};
export const sessionMW = async (
req: Request,
res: Response,
next: Function
) => {
const ctx = {
headers: fromNodeHeaders(req.headers),
setCookie: (name: string, data: string, options: any) => {
console.log(`Setting cookie: ${name}`);
res.cookie(name, data, {
...options,
maxAge: config.sessionCache_maxAge * 1000, // 5 minutes
});
},
};
const session = await auth.api.getSession(ctx);

if (!session) {
return res.status(401).json({ error: "Unauthorized: Invalid session" });
}

req.session = session;
next();
};
However, it works in v1.1.21 but not in v1.2.4 I'm still trying to figure out how to do it
6 replies