Rename accounts to users to be consistent with the new naming scheme where account only referes to the logged in user of the session and implement live updates of users via a user store which listens for updates from the event stream.
20 lines
545 B
TypeScript
20 lines
545 B
TypeScript
import { readSubscriptions } from "~/server/database";
|
|
import type { ApiSession } from "~/shared/types/api";
|
|
|
|
export default defineEventHandler(async (event): Promise<ApiSession | undefined> => {
|
|
const session = await getServerSession(event);
|
|
if (!session)
|
|
return;
|
|
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: session.account,
|
|
push,
|
|
};
|
|
})
|