Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions apps/sim/app/api/credential-sets/invitations/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { db } from '@sim/db'
import { credentialSet, credentialSetInvitation, organization, user } from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { and, eq, gt, isNull, or } from 'drizzle-orm'
import { and, eq, gt } from 'drizzle-orm'
import { NextResponse } from 'next/server'
import { getSession } from '@/lib/auth'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
Expand All @@ -16,6 +16,9 @@ export const GET = withRouteHandler(async () => {
}

try {
// Scope to invitations addressed to the caller's own email only. Open-link
// (null-email) invites carry a bearer token redeemed via the out-of-band URL
// and must never be listed, or any user could accept another org's invite.
const invitations = await db
.select({
invitationId: credentialSetInvitation.id,
Expand All @@ -37,10 +40,7 @@ export const GET = withRouteHandler(async () => {
.leftJoin(user, eq(credentialSetInvitation.invitedBy, user.id))
.where(
and(
or(
eq(credentialSetInvitation.email, session.user.email),
isNull(credentialSetInvitation.email)
),
eq(credentialSetInvitation.email, session.user.email),
eq(credentialSetInvitation.status, 'pending'),
gt(credentialSetInvitation.expiresAt, new Date())
)
Expand Down
Loading