Skip to content

Commit 90a011f

Browse files
committed
chore(sso): final-review polish — trim script read, unify copy, doc migration edge
Cosmetic cleanup from a final 4-track adversarial review (no bugs found in the new logic): - Self-host script: narrow the pre-transaction existence read to select({ id }) instead of SELECT * (it only feeds a log line now). - Unify invalid-domain copy ("for example acme.com") and the verified-elsewhere 409 wording ("is already verified by another organization") across routes. - p-3 shorthand on the domain row card. - Document the migration's rare two-orgs-share-a-domain grandfather behavior (login unaffected; validated no such duplicates in prod).
1 parent 2223c25 commit 90a011f

5 files changed

Lines changed: 13 additions & 5 deletions

File tree

apps/sim/app/api/auth/sso/register/route.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
117117

118118
const domain = normalizeSSODomain(body.domain)
119119
if (!domain) {
120-
return NextResponse.json({ error: 'Enter a valid domain like company.com' }, { status: 400 })
120+
return NextResponse.json(
121+
{ error: 'Enter a valid domain, for example acme.com' },
122+
{ status: 400 }
123+
)
121124
}
122125

123126
// Security gate: configuring org SSO for a domain requires the org to have

apps/sim/app/api/organizations/[id]/domains/[domainId]/verify/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const POST = withRouteHandler(
9090
.limit(1)
9191
if (verifiedElsewhere && verifiedElsewhere.organizationId !== organizationId) {
9292
return NextResponse.json(
93-
{ error: 'This domain was verified by another organization' },
93+
{ error: 'This domain is already verified by another organization' },
9494
{ status: 409 }
9595
)
9696
}
@@ -117,7 +117,7 @@ export const POST = withRouteHandler(
117117
} catch (error) {
118118
if (getPostgresErrorCode(error) === '23505') {
119119
return NextResponse.json(
120-
{ error: 'This domain was verified by another organization' },
120+
{ error: 'This domain is already verified by another organization' },
121121
{ status: 409 }
122122
)
123123
}

apps/sim/ee/sso/components/domain-settings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function DomainRow({ organizationId, domain, onRemove }: DomainRowProps) {
5151
}
5252

5353
return (
54-
<div className='flex flex-col gap-3 rounded-lg border border-[var(--border-1)] px-3 py-3'>
54+
<div className='flex flex-col gap-3 rounded-lg border border-[var(--border-1)] p-3'>
5555
<div className='flex items-center justify-between gap-2'>
5656
<span className='truncate text-[var(--text-body)] text-sm'>{domain.domain}</span>
5757
<div className='flex items-center gap-2'>

packages/db/migrations/0266_sso_domain_verification.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ CREATE UNIQUE INDEX "sso_domain_verified_unique" ON "sso_domain" USING btree ("d
2525
-- keeps the DISTINCT ON dedup key identical to the inserted value, so the
2626
-- global partial unique index on verified rows can never be violated. The
2727
-- token is a placeholder since these rows are already verified.
28+
-- NOTE: if two orgs somehow share a domain (possible only for data predating the
29+
-- register-route conflict check), DISTINCT ON grandfathers the lowest org_id and
30+
-- the other org gets no row. Its existing SSO login is unaffected (login never
31+
-- reads sso_domain); it just can't re-register that domain until an admin
32+
-- resolves the duplicate. Validated against prod: no such duplicates exist.
2833
INSERT INTO "sso_domain" ("id", "organization_id", "domain", "status", "verification_token", "verified_at", "created_at", "updated_at")
2934
SELECT DISTINCT ON ("norm_domain")
3035
gen_random_uuid()::text,

packages/db/scripts/register-sso-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ async function registerSSOProvider(): Promise<boolean> {
561561
}
562562

563563
const existingProviders = await db
564-
.select()
564+
.select({ id: ssoProvider.id })
565565
.from(ssoProvider)
566566
.where(eq(ssoProvider.providerId, ssoConfig.providerId))
567567

0 commit comments

Comments
 (0)