Move /api/account to /api/auth/account
An account refers to the user the active session is logged in as. As such it doesn't make sense outside of the /auth API paths that deals with the current authenticated user. Move /api/account to /api/auth/account to reflect this.
This commit is contained in:
parent
e7dc00db54
commit
04b9707272
6 changed files with 5 additions and 5 deletions
|
@ -1,45 +0,0 @@
|
|||
import {
|
||||
readAccounts, readSessions, readSubscriptions,
|
||||
writeAccounts, writeSessions, writeSubscriptions,
|
||||
} from "~/server/database";
|
||||
import { cancelAccountStreams } from "~/server/streams";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const accountSession = await requireAccountSession(event);
|
||||
|
||||
let accounts = await readAccounts();
|
||||
const sessionAccount = accounts.find(
|
||||
account => account.id === accountSession.accountId
|
||||
);
|
||||
if (!sessionAccount) {
|
||||
throw Error("Account does not exist");
|
||||
}
|
||||
|
||||
// Remove sessions for this account
|
||||
const removedSessionIds = new Set<number>();
|
||||
let sessions = await readSessions();
|
||||
sessions = sessions.filter(session => {
|
||||
if (session.accountId === accountSession.accountId) {
|
||||
removedSessionIds.add(session.id);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
cancelAccountStreams(accountSession.accountId);
|
||||
await writeSessions(sessions);
|
||||
await deleteCookie(event, "session");
|
||||
|
||||
// Remove subscriptions for this account
|
||||
let subscriptions = await readSubscriptions();
|
||||
subscriptions = subscriptions.filter(
|
||||
subscription => !removedSessionIds.has(subscription.sessionId)
|
||||
);
|
||||
await writeSubscriptions(subscriptions);
|
||||
|
||||
// Remove the account
|
||||
accounts = accounts.filter(account => account.id !== accountSession.accountId);
|
||||
await writeAccounts(accounts);
|
||||
|
||||
// Update Schedule counts.
|
||||
await updateScheduleInterestedCounts(accounts);
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue