2025-03-07 14:11:07 +01:00
|
|
|
import { readAccounts, readSubscriptions } from "~/server/database";
|
2025-03-07 12:41:57 +01:00
|
|
|
import { AccountSession } from "~/shared/types/account";
|
|
|
|
|
2025-03-07 14:11:07 +01:00
|
|
|
export default defineEventHandler(async (event): Promise<AccountSession | undefined> => {
|
2025-06-09 16:51:05 +02:00
|
|
|
const session = await getServerSession(event);
|
2025-03-07 12:41:57 +01:00
|
|
|
if (!session)
|
|
|
|
return;
|
|
|
|
const accounts = await readAccounts();
|
2025-03-07 14:11:07 +01:00
|
|
|
const subscriptions = await readSubscriptions();
|
|
|
|
const push = Boolean(
|
|
|
|
subscriptions.find(sub => sub.type === "push" && sub.sessionId === session.id)
|
|
|
|
);
|
2025-03-07 12:41:57 +01:00
|
|
|
|
2025-06-09 16:51:05 +02:00
|
|
|
await refreshServerSession(event, session);
|
2025-03-11 16:30:51 +01:00
|
|
|
|
2025-03-07 12:41:57 +01:00
|
|
|
return {
|
|
|
|
id: session.id,
|
|
|
|
account: accounts.find(account => account.id === session.accountId)!,
|
2025-03-07 14:11:07 +01:00
|
|
|
push,
|
|
|
|
};
|
2025-03-07 12:41:57 +01:00
|
|
|
})
|