Skip to content

Commit 0263d1e

Browse files
committed
updated invitation log
1 parent d4e6872 commit 0263d1e

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

apps/sim/app/api/workspaces/invitations/[invitationId]/route.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ export async function GET(
2727
// For token-based acceptance flows, redirect to login
2828
if (isAcceptFlow) {
2929
return NextResponse.redirect(
30-
new URL(`/invite/${token}?token=${token}`, env.NEXT_PUBLIC_APP_URL || 'https://sim.ai')
30+
new URL(
31+
`/invite/${invitationId}?token=${token}`,
32+
env.NEXT_PUBLIC_APP_URL || 'https://sim.ai'
33+
)
3134
)
3235
}
3336
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
@@ -51,7 +54,10 @@ export async function GET(
5154
if (new Date() > new Date(invitation.expiresAt)) {
5255
if (isAcceptFlow) {
5356
return NextResponse.redirect(
54-
new URL(`/invite/${token}?error=expired`, env.NEXT_PUBLIC_APP_URL || 'https://sim.ai')
57+
new URL(
58+
`/invite/${invitation.id}?error=expired`,
59+
env.NEXT_PUBLIC_APP_URL || 'https://sim.ai'
60+
)
5561
)
5662
}
5763
return NextResponse.json({ error: 'Invitation has expired' }, { status: 400 })
@@ -67,7 +73,7 @@ export async function GET(
6773
if (isAcceptFlow) {
6874
return NextResponse.redirect(
6975
new URL(
70-
`/invite/${token}?error=workspace-not-found`,
76+
`/invite/${invitation.id}?error=workspace-not-found`,
7177
env.NEXT_PUBLIC_APP_URL || 'https://sim.ai'
7278
)
7379
)
@@ -79,7 +85,7 @@ export async function GET(
7985
if (invitation.status !== ('pending' as WorkspaceInvitationStatus)) {
8086
return NextResponse.redirect(
8187
new URL(
82-
`/invite/${token}?error=already-processed`,
88+
`/invite/${invitation.id}?error=already-processed`,
8389
env.NEXT_PUBLIC_APP_URL || 'https://sim.ai'
8490
)
8591
)
@@ -97,7 +103,7 @@ export async function GET(
97103
if (!userData) {
98104
return NextResponse.redirect(
99105
new URL(
100-
`/invite/${token}?error=user-not-found`,
106+
`/invite/${invitation.id}?error=user-not-found`,
101107
env.NEXT_PUBLIC_APP_URL || 'https://sim.ai'
102108
)
103109
)
@@ -108,7 +114,7 @@ export async function GET(
108114
if (!isValidMatch) {
109115
return NextResponse.redirect(
110116
new URL(
111-
`/invite/${token}?error=email-mismatch`,
117+
`/invite/${invitation.id}?error=email-mismatch`,
112118
env.NEXT_PUBLIC_APP_URL || 'https://sim.ai'
113119
)
114120
)

apps/sim/app/api/workspaces/invitations/route.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export async function POST(req: NextRequest) {
206206
to: email,
207207
inviterName: session.user.name || session.user.email || 'A user',
208208
workspaceName: workspaceDetails.name,
209+
invitationId: invitationData.id,
209210
token: token,
210211
})
211212

@@ -221,17 +222,19 @@ async function sendInvitationEmail({
221222
to,
222223
inviterName,
223224
workspaceName,
225+
invitationId,
224226
token,
225227
}: {
226228
to: string
227229
inviterName: string
228230
workspaceName: string
231+
invitationId: string
229232
token: string
230233
}) {
231234
try {
232235
const baseUrl = env.NEXT_PUBLIC_APP_URL || 'https://sim.ai'
233-
// Always use the client-side invite route with token parameter
234-
const invitationLink = `${baseUrl}/invite/${token}?token=${token}`
236+
// Use invitation ID in path, token in query parameter for security
237+
const invitationLink = `${baseUrl}/invite/${invitationId}?token=${token}`
235238

236239
const emailHtml = await render(
237240
WorkspaceInvitationEmail({

apps/sim/app/invite/[id]/invite.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,10 @@ export default function Invite() {
5151
async function fetchInvitationDetails() {
5252
setIsLoading(true)
5353
try {
54-
const workspaceInviteResponse = await fetch(
55-
`/api/workspaces/invitations/${token}?token=${token}`,
56-
{
57-
method: 'GET',
58-
}
59-
)
54+
// Fetch invitation details using the invitation ID from the URL path
55+
const workspaceInviteResponse = await fetch(`/api/workspaces/invitations/${inviteId}`, {
56+
method: 'GET',
57+
})
6058

6159
if (workspaceInviteResponse.ok) {
6260
const data = await workspaceInviteResponse.json()
@@ -118,7 +116,7 @@ export default function Invite() {
118116
setIsAccepting(true)
119117

120118
if (invitationType === 'workspace') {
121-
window.location.href = `/api/workspaces/invitations/${encodeURIComponent(token || '')}?token=${encodeURIComponent(token || '')}`
119+
window.location.href = `/api/workspaces/invitations/${encodeURIComponent(inviteId)}?token=${encodeURIComponent(token || '')}`
122120
} else {
123121
try {
124122
const response = await client.organization.acceptInvitation({

0 commit comments

Comments
 (0)