Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix: create and then delete scim directories

Marc Seitz7de41925ac3c
diff --git a/app/(ee)/api/teams/[teamId]/directory-sync/route.ts b/app/(ee)/api/teams/[teamId]/directory-sync/route.ts
index 12e9fd64..9e7eb57f 100644
--- a/app/(ee)/api/teams/[teamId]/directory-sync/route.ts
+++ b/app/(ee)/api/teams/[teamId]/directory-sync/route.ts
@@ -97,17 +97,13 @@ export async function POST(
const body = await req.json();
const { name, type, currentDirectoryId } = body;
- const [result] = await Promise.all([
- directorySyncController.directories.create({
- tenant: teamId,
- product: jacksonProduct,
- name: name || "Papermark SCIM Directory",
- type: type || "azure-scim-v2",
- }),
- // If replacing an existing directory, delete the old one
- currentDirectoryId &&
- directorySyncController.directories.delete(currentDirectoryId),
- ]);
+ // Create the new directory first; only delete the old one on success
+ const result = await directorySyncController.directories.create({
+ tenant: teamId,
+ product: jacksonProduct,
+ name: name || "Papermark SCIM Directory",
+ type: type || "azure-scim-v2",
+ });
if (result.error) {
return NextResponse.json(
@@ -116,6 +112,11 @@ export async function POST(
);
}
+ // If replacing an existing directory, delete the old one after successful create
+ if (currentDirectoryId) {
+ await directorySyncController.directories.delete(currentDirectoryId);
+ }
+
return NextResponse.json(result, { status: 201 });
} catch (error: any) {
console.error("[SCIM] Create directory error:", error);