fix: harden booking and meeting flows

This commit is contained in:
2026-09-17 02:42:27 +02:00
parent cb30ecade9
commit 66710fc65c
42 changed files with 683 additions and 608 deletions
+19
View File
@@ -0,0 +1,19 @@
import type { CollectionAfterChangeHook } from "payload";
import type { Event } from "@/payload-types";
import { meetingAccessVersion } from "./access";
import { getLiveKitRoomName, getLiveKitRoomService } from "./livekit";
/** Disconnect the previous room when its password, schedule or access changes. */
export const revokeChangedMeeting: CollectionAfterChangeHook<Event> = async ({ doc, previousDoc, req }) => {
if (!previousDoc?.isOnline || !previousDoc.slug || !process.env.LIVEKIT_URL || !process.env.MEETING_SESSION_SECRET) return doc;
const previousVersion = meetingAccessVersion(previousDoc);
if (previousVersion === meetingAccessVersion(doc)) return doc;
try {
const service = getLiveKitRoomService();
const name = getLiveKitRoomName(previousDoc.slug, previousVersion);
if ((await service.listRooms([name])).length) await service.deleteRoom(name);
} catch (err) {
req.payload.logger.error({ err, msg: "Could not disconnect revoked meeting room" });
}
return doc;
};