The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Sync staging members from production and keep invite redirects moving
Kiran Kab30fd54ed4e
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/users/route.tsindex c03308e599..6f177ce8c3 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts@@ -187,7 +187,7 @@ export const DELETE = withWorkspace(});}- await Promise.allSettled([+ await Promise.all([// Remove the user from the workspaceprisma.projectUsers.delete({where: {@@ -235,6 +235,8 @@ export const DELETE = withWorkspace(});}- return NextResponse.json({});+ return NextResponse.json({+ userId,+ });},);diff --git a/apps/web/app/app.dub.co/(auth)/invites/[code]/page.tsx b/apps/web/app/app.dub.co/(auth)/invites/[code]/page.tsxindex d070ab3308..35364283dc 100644--- a/apps/web/app/app.dub.co/(auth)/invites/[code]/page.tsx+++ b/apps/web/app/app.dub.co/(auth)/invites/[code]/page.tsx@@ -81,11 +81,13 @@ async function VerifyInvite({ code }: { code: string }) {// check if user is already in the workspaceif (workspace.users.length > 0) {- await syncStagingWorkspaceJob.dispatch({- action: "add-member",- workspaceId: workspace.id,- userId: session.user.id,- });+ waitUntil(+ syncStagingWorkspaceJob.dispatch({+ action: "add-member",+ workspaceId: workspace.id,+ userId: session.user.id,+ }),+ );redirect(`/${workspace.slug}`);}diff --git a/apps/web/lib/jobs/handlers/sync-staging-workspace-job.ts b/apps/web/lib/jobs/handlers/sync-staging-workspace-job.tsindex abb04c115d..44e03bb1c8 100644--- a/apps/web/lib/jobs/handlers/sync-staging-workspace-job.ts+++ b/apps/web/lib/jobs/handlers/sync-staging-workspace-job.ts@@ -67,21 +67,9 @@ export const syncStagingWorkspaceJob = defineJob({switch (payload.action) {case "add-member":- await addMember({- workspace,- userId: payload.userId,- });- break;-case "update-member-role":- await updateMemberRole({- workspace,- userId: payload.userId,- });- break;-case "remove-member":- await removeMember({+ await syncMember({workspace,userId: payload.userId,});@@ -94,8 +82,7 @@ export const syncStagingWorkspaceJob = defineJob({},});-// We don't sync the machine user from the production workspace to the staging workspace-async function addMember({+async function syncMember({workspace,userId,}: {@@ -123,91 +110,31 @@ async function addMember({},});- if (!member || member.user.isMachine) {- return;- }-- await prisma.projectUsers.upsert({- where: {- userId_projectId: {- userId,- projectId: workspace.stagingWorkspaceId,- },- },- create: {- projectId: workspace.stagingWorkspaceId,- userId,- role: member.role,- notificationPreference: {- create: {},- },- },- update: {},- });-}--async function updateMemberRole({- workspace,- userId,-}: {- workspace: ProductionWorkspace;- userId: string;-}) {- if (!workspace.stagingWorkspaceId) {+ // We don't sync the machine user from the production workspace to the staging workspace+ if (member?.user.isMachine) {return;}- const member = await prisma.projectUsers.findUnique({- where: {- userId_projectId: {- userId,- projectId: workspace.id,- },- },- select: {- role: true,- user: {- select: {- isMachine: true,+ if (member) {+ await prisma.projectUsers.upsert({+ where: {+ userId_projectId: {+ userId,+ projectId: workspace.stagingWorkspaceId,},},- },- });-- // We don't sync the machine user from the production workspace to the staging workspace- if (!member || member.user.isMachine) {- return;- }-- await prisma.projectUsers.upsert({- where: {- userId_projectId: {- userId,+ create: {projectId: workspace.stagingWorkspaceId,+ userId,+ role: member.role,+ notificationPreference: {+ create: {},+ },},- },- create: {- projectId: workspace.stagingWorkspaceId,- userId,- role: member.role,- notificationPreference: {- create: {},+ update: {+ role: member.role,},- },- update: {- role: member.role,- },- });-}--async function removeMember({- workspace,- userId,-}: {- workspace: ProductionWorkspace;- userId: string;-}) {- if (!workspace.stagingWorkspaceId) {+ });return;}