Rename AcountSession to ServerSession
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".
This commit is contained in:
parent
16191a8dd2
commit
251e83f640
15 changed files with 39 additions and 36 deletions
|
@ -5,11 +5,11 @@ import {
|
|||
import { cancelAccountStreams } from "~/server/streams";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const accountSession = await requireAccountSession(event);
|
||||
const serverSession = await requireServerSession(event);
|
||||
|
||||
let accounts = await readAccounts();
|
||||
const sessionAccount = accounts.find(
|
||||
account => account.id === accountSession.accountId
|
||||
account => account.id === serverSession.accountId
|
||||
);
|
||||
if (!sessionAccount) {
|
||||
throw Error("Account does not exist");
|
||||
|
@ -19,13 +19,13 @@ export default defineEventHandler(async (event) => {
|
|||
const removedSessionIds = new Set<number>();
|
||||
let sessions = await readSessions();
|
||||
sessions = sessions.filter(session => {
|
||||
if (session.accountId === accountSession.accountId) {
|
||||
if (session.accountId === serverSession.accountId) {
|
||||
removedSessionIds.add(session.id);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
cancelAccountStreams(accountSession.accountId);
|
||||
cancelAccountStreams(serverSession.accountId);
|
||||
await writeSessions(sessions);
|
||||
await deleteCookie(event, "session");
|
||||
|
||||
|
@ -37,7 +37,7 @@ export default defineEventHandler(async (event) => {
|
|||
await writeSubscriptions(subscriptions);
|
||||
|
||||
// Remove the account
|
||||
accounts = accounts.filter(account => account.id !== accountSession.accountId);
|
||||
accounts = accounts.filter(account => account.id !== serverSession.accountId);
|
||||
await writeAccounts(accounts);
|
||||
|
||||
// Update Schedule counts.
|
||||
|
|
|
@ -3,7 +3,7 @@ import { readAccounts, writeAccounts } from "~/server/database";
|
|||
import { DateTime } from "luxon";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const session = await requireAccountSession(event);
|
||||
const session = await requireServerSession(event);
|
||||
const body: Pick<Account, "interestedIds" | "timezone"> = await readBody(event);
|
||||
if (
|
||||
body.interestedIds !== undefined
|
||||
|
|
|
@ -2,7 +2,7 @@ import { readAccounts, writeAccounts, nextAccountId } from "~/server/database";
|
|||
import { Account } from "~/shared/types/account";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
let session = await getAccountSession(event);
|
||||
let session = await getServerSession(event);
|
||||
if (session) {
|
||||
throw createError({
|
||||
status: 409,
|
||||
|
@ -49,5 +49,5 @@ export default defineEventHandler(async (event) => {
|
|||
|
||||
accounts.push(account);
|
||||
await writeAccounts(accounts);
|
||||
await setAccountSession(event, account.id);
|
||||
await setServerSession(event, account.id);
|
||||
})
|
||||
|
|
|
@ -14,5 +14,5 @@ export default defineEventHandler(async (event) => {
|
|||
return new Response(undefined, { status: 403 })
|
||||
}
|
||||
|
||||
await setAccountSession(event, account.id);
|
||||
await setServerSession(event, account.id);
|
||||
})
|
||||
|
|
|
@ -2,7 +2,7 @@ import { readAccounts } from "~/server/database";
|
|||
import { cancelSessionStreams } from "~/server/streams";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const session = await getAccountSession(event);
|
||||
const session = await getServerSession(event);
|
||||
if (session) {
|
||||
const accounts = await readAccounts();
|
||||
const account = accounts.find(
|
||||
|
@ -19,5 +19,5 @@ export default defineEventHandler(async (event) => {
|
|||
if (session) {
|
||||
cancelSessionStreams(session.id);
|
||||
}
|
||||
await clearAccountSession(event);
|
||||
await clearServerSession(event);
|
||||
})
|
||||
|
|
|
@ -2,7 +2,7 @@ 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);
|
||||
const session = await getServerSession(event);
|
||||
if (!session)
|
||||
return;
|
||||
const accounts = await readAccounts();
|
||||
|
@ -11,7 +11,7 @@ export default defineEventHandler(async (event): Promise<AccountSession | undefi
|
|||
subscriptions.find(sub => sub.type === "push" && sub.sessionId === session.id)
|
||||
);
|
||||
|
||||
await refreshAccountSession(event, session);
|
||||
await refreshServerSession(event, session);
|
||||
|
||||
return {
|
||||
id: session.id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue