Skip to content

Commit 84d00ae

Browse files
HugoGresseclaude
andcommitted
Fix event creation denied by private-key rule
The new event creation batched the project doc and its private/integration API-key doc together. The private-doc create rule does get(project) (isAdmin), which in a batch evaluates against pre-commit state where the project doc does not exist yet, so the get errors and the write is denied (PERMISSION_DENIED at the /private rule). Write sequentially instead: create the project doc, then the private key doc. By then get(project) resolves and the owner check passes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 5c7f76b commit 84d00ae

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

src/admin/project/core/actions/newProject.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,23 @@ export const newProject =
4949
}
5050
}
5151

52-
// Write the project doc and its (member-only) API key atomically. The
53-
// key goes in a private subcollection, never on the world-readable
54-
// project doc.
52+
// Create the project doc first, then its (member-only) API key in a
53+
// private subcollection — never on the world-readable project doc. The
54+
// writes must be sequential, not batched: the private-doc create rule
55+
// does get(project), which in a batch would see the project as
56+
// not-yet-created and fail.
5557
const projectRef = fireStoreMainInstance
5658
.collection('projects')
5759
.doc(projectId)
58-
const batch = fireStoreMainInstance.batch()
59-
batch.set(projectRef, projectData)
60-
batch.set(projectRef.collection('private').doc('integration'), {
61-
apiKey: generateProjectApiKey(),
62-
})
6360

64-
return await batch
65-
.commit()
61+
return await projectRef
62+
.set(projectData)
63+
.then(() =>
64+
projectRef
65+
.collection('private')
66+
.doc('integration')
67+
.set({ apiKey: generateProjectApiKey() })
68+
)
6669
.then(() => {
6770
dispatch(
6871
addNotification({

0 commit comments

Comments
 (0)