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".
16 lines
580 B
TypeScript
16 lines
580 B
TypeScript
import { readSubscriptions, writeSubscriptions } from "~/server/database";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const session = await requireServerSession(event);
|
|
const subscriptions = await readSubscriptions();
|
|
const existingIndex = subscriptions.findIndex(
|
|
sub => sub.type === "push" && sub.sessionId === session.id
|
|
);
|
|
if (existingIndex !== -1) {
|
|
subscriptions.splice(existingIndex, 1);
|
|
} else {
|
|
return { message: "No subscription registered."};
|
|
}
|
|
await writeSubscriptions(subscriptions);
|
|
return { message: "Existing subscription removed."};
|
|
});
|