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".
23 lines
602 B
TypeScript
23 lines
602 B
TypeScript
import { readAccounts } from "~/server/database";
|
|
import { cancelSessionStreams } from "~/server/streams";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const session = await getServerSession(event);
|
|
if (session) {
|
|
const accounts = await readAccounts();
|
|
const account = accounts.find(
|
|
account => account.id === session.accountId
|
|
);
|
|
if (account && account.type === "anonymous") {
|
|
throw createError({
|
|
status: 409,
|
|
message: "Cannot log out of an anonymous account",
|
|
});
|
|
}
|
|
}
|
|
|
|
if (session) {
|
|
cancelSessionStreams(session.id);
|
|
}
|
|
await clearServerSession(event);
|
|
})
|