fix(fe2): accept invite before onboarding after sign up (#2491)
* explicitly ordering global middlewares * various subscription fixes & WIP project invite middleware * SSR invite accept & toast notifs seem to work * backend support for mixpanel * mixpanel be logic -> shared * minor fix * finissh * lint fix * minor comment adjustments * better adblock handling
This commit is contained in:
committed by
GitHub
parent
790d97383c
commit
ee5ae8af62
@@ -16,6 +16,7 @@ import {
|
||||
DeleteServerOnlyInvites,
|
||||
DeleteStreamInvite,
|
||||
FindInvite,
|
||||
FindResource,
|
||||
FindServerInvite,
|
||||
FindStreamInvite,
|
||||
UpdateAllInviteTargets
|
||||
@@ -24,6 +25,7 @@ import {
|
||||
FinalizeStreamInvite,
|
||||
ResendInviteEmail
|
||||
} from '@/modules/serverinvites/services/operations'
|
||||
import { StreamNotFoundError } from '@/modules/core/errors/stream'
|
||||
|
||||
/**
|
||||
* Resolve the relative auth redirect path, after registering with an invite
|
||||
@@ -100,10 +102,12 @@ export const finalizeInvitedServerRegistrationFactory =
|
||||
export const finalizeStreamInviteFactory =
|
||||
({
|
||||
findStreamInvite,
|
||||
deleteInvitesByTarget
|
||||
deleteInvitesByTarget,
|
||||
findResource
|
||||
}: {
|
||||
findStreamInvite: FindStreamInvite
|
||||
deleteInvitesByTarget: DeleteInvitesByTarget
|
||||
findResource: FindResource
|
||||
}): FinalizeStreamInvite =>
|
||||
async (accept, streamId, token, userId) => {
|
||||
const invite = await findStreamInvite(streamId, {
|
||||
@@ -120,6 +124,26 @@ export const finalizeStreamInviteFactory =
|
||||
})
|
||||
}
|
||||
|
||||
const stream = await findResource(invite)
|
||||
if (!stream) {
|
||||
throw new StreamNotFoundError('Stream not found for invite', {
|
||||
info: {
|
||||
streamId,
|
||||
token,
|
||||
userId
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Delete all invites to this stream
|
||||
// We're doing this before processing the invite, to prevent a PROJECT UPDATED event
|
||||
// from being fired with the invites still attached
|
||||
await deleteInvitesByTarget(
|
||||
buildUserTarget(userId)!,
|
||||
ResourceTargets.Streams,
|
||||
streamId
|
||||
)
|
||||
|
||||
// Invite found - accept or decline
|
||||
if (accept) {
|
||||
// Add access for user
|
||||
@@ -128,27 +152,14 @@ export const finalizeStreamInviteFactory =
|
||||
await addOrUpdateStreamCollaborator(streamId, userId, role!, inviterId, null, {
|
||||
fromInvite: true
|
||||
})
|
||||
|
||||
// Delete all invites to this stream
|
||||
await deleteInvitesByTarget(
|
||||
buildUserTarget(userId)!,
|
||||
ResourceTargets.Streams,
|
||||
streamId
|
||||
)
|
||||
} else {
|
||||
await addStreamInviteDeclinedActivity({
|
||||
streamId,
|
||||
inviteTargetId: userId,
|
||||
inviterId: invite.inviterId
|
||||
inviterId: invite.inviterId,
|
||||
stream
|
||||
})
|
||||
}
|
||||
|
||||
// Delete all invites to this stream
|
||||
await deleteInvitesByTarget(
|
||||
buildUserTarget(userId)!,
|
||||
ResourceTargets.Streams,
|
||||
streamId
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user