Set a max age for the session cookie to prevent it from expiring when the browser is closed. To prevent the age limit from being being reached the session cookie is refreshed every time the session is loaded. This should fix login being lost when the browser is stopped.
21 lines
652 B
TypeScript
21 lines
652 B
TypeScript
import { readAccounts, readSubscriptions } from "~/server/database";
|
|
import { AccountSession } from "~/shared/types/account";
|
|
|
|
export default defineEventHandler(async (event): Promise<AccountSession | undefined> => {
|
|
const session = await getAccountSession(event);
|
|
if (!session)
|
|
return;
|
|
const accounts = await readAccounts();
|
|
const subscriptions = await readSubscriptions();
|
|
const push = Boolean(
|
|
subscriptions.find(sub => sub.type === "push" && sub.sessionId === session.id)
|
|
);
|
|
|
|
await refreshAccountSession(event, session);
|
|
|
|
return {
|
|
id: session.id,
|
|
account: accounts.find(account => account.id === session.accountId)!,
|
|
push,
|
|
};
|
|
})
|