owltide/server/api/auth/session.delete.ts

24 lines
602 B
TypeScript
Raw Normal View History

2025-03-07 23:53:57 +01:00
import { readAccounts } from "~/server/database";
import { cancelSessionStreams } from "~/server/streams";
2025-03-07 23:53:57 +01:00
export default defineEventHandler(async (event) => {
const session = await getServerSession(event);
2025-03-07 23:53:57 +01:00
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);
})