Start the work of clearly distingushing client side types, server side types and types shared over the API by renaming "AccountSession" and "Session" names used on the server to "ServerSession".
21 lines
650 B
TypeScript
21 lines
650 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 getServerSession(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 refreshServerSession(event, session);
|
|
|
|
return {
|
|
id: session.id,
|
|
account: accounts.find(account => account.id === session.accountId)!,
|
|
push,
|
|
};
|
|
})
|