Refactor user storage and update
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.
This commit is contained in:
parent
6336ccdb96
commit
3be7f8be05
24 changed files with 331 additions and 182 deletions
|
@ -1,11 +1,10 @@
|
|||
import { readAccounts, readSubscriptions } from "~/server/database";
|
||||
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 accounts = await readAccounts();
|
||||
const subscriptions = await readSubscriptions();
|
||||
const push = Boolean(
|
||||
subscriptions.find(sub => sub.type === "push" && sub.sessionId === session.id)
|
||||
|
@ -15,7 +14,7 @@ export default defineEventHandler(async (event): Promise<ApiSession | undefined>
|
|||
|
||||
return {
|
||||
id: session.id,
|
||||
account: accounts.find(account => account.id === session.accountId)!,
|
||||
account: session.account,
|
||||
push,
|
||||
};
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue