Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix(db): read invites from primary instead of replica (avoid race condition) #134

Carl-Gerhard Lindesvärde58e89868321
diff --git a/packages/db/src/services/organization.service.ts b/packages/db/src/services/organization.service.ts
index 66f8dfaed..5b6c646c8 100644
--- a/packages/db/src/services/organization.service.ts
+++ b/packages/db/src/services/organization.service.ts
@@ -133,7 +133,9 @@ export async function connectUserToOrganization({
user: User;
inviteId: string;
}) {
- const invite = await db.invite.findUnique({
+ // Use primary since before this we might have just created the invite
+ // If we use replica it might not find the invite
+ const invite = await db.$primary().invite.findUnique({
where: {
id: inviteId,
},