owltide/server/api/auth/session.get.ts
Hornwitser 52dfde95d1 Tie push subscriptions to current session
If a user logs out from a device the expectation should be that device
no longer having any association with the user's account.  Any existing
push notifications should thefore be removed on server.  For this reason
tie push notifications to a session, and remove them when the session is
deleted.
2025-03-07 15:47:48 +01:00

19 lines
605 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)
);
return {
id: session.id,
account: accounts.find(account => account.id === session.accountId)!,
push,
};
})