Skip to content

feat(organizations): add verified domain auto-join - #5437

Open
jrf0110 wants to merge 1 commit into
mainfrom
feature/verified-domains
Open

feat(organizations): add verified domain auto-join#5437
jrf0110 wants to merge 1 commit into
mainfrom
feature/verified-domains

Conversation

@jrf0110

@jrf0110 jrf0110 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add WorkOS-backed verified domain claims with canonical validation, ownership constraints, lifecycle auditing, and organization settings UI
  • automatically add matching authenticated users as ordinary organization members across browser, WorkOS SSO, and native authentication
  • prefer the verified-domain organization after sign-in while preserving personal accounts, unrelated memberships, explicit destinations, and removal tombstones

Validation

  • 11 focused Jest suites, 269 tests passed
  • pnpm --filter web typecheck
  • scripts/typecheck-all.sh --changes-only
  • pnpm --filter web lint
  • pnpm --filter @kilocode/db exec drizzle-kit check
  • pnpm format:check
  • pnpm drizzle generate reports no schema changes
  • git diff --check

Remaining validation gaps

  • pnpm drizzle:verify-bootstrap exits before PostgreSQL receives SQL with a non-diagnostic Drizzle undefined error; migration consistency and database-backed feature tests pass
  • WorkOS behavior is covered with provider mocks rather than a live verification flow
  • popup and responsive behavior have component coverage but no browser smoke test

}

if (!isAccountLinking) {
await ensureVerifiedDomainOrganizationMembership(result.user.id);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL: Unproven social emails still trigger verified-domain auto-join

ensureVerifiedDomainOrganizationMembership runs for every non-linking sign-in, including GitHub/GitLab/Discord/LinkedIn. This file already treats those providers as never proving email (profileProvesEmailOwnership) and therefore refuses auto-link, but a new GitHub signup with user@acme.com still becomes an ordinary member of the Acme org.

Gate admission on the same proof used for autoLinkToExistingUser (isEmailAuth || isFakeLogin || profileProvesEmailOwnership(profile)), or persist a verified-email bit and check it inside ensureVerifiedDomainOrganizationMembership. The sign-in test currently locks in the insecure GitHub path.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

const createClaim = useMutation(
trpc.organizations.verifiedDomains.create.mutationOptions({
onSuccess: async data => {
if (verificationPortal.current) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Closed or unmounted verification popup is not cleaned up

A reserved Window stays truthy after the user closes it, so verificationPortal.current.location.href = … throws. That skips onError, so verificationRequestPending never resets and later Claim / Open verification clicks no-op until remount.

There is also no unmount effect to close the reserved tab, so navigating away mid-mutation leaks the popup.

Check closed before assigning, reset the pending flag in finally, and close the reserved window on unmount.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
apps/web/src/lib/user/server.ts 950 Unproven social emails still trigger verified-domain auto-join

WARNING

File Line Issue
apps/web/src/components/organizations/VerifiedDomainsCard.tsx 261 Closed or unmounted verification popup is not cleaned up
Files Reviewed (31 files)
  • .kilo/skills/specs/SKILL.md - 0 issues
  • .specs/verified-domains.md - 0 issues
  • apps/web/src/app/api/auth/native/token/route.test.ts - 0 issues
  • apps/web/src/app/api/auth/native/token/route.ts - 0 issues
  • apps/web/src/app/api/profile/route.test.ts - 0 issues
  • apps/web/src/app/api/profile/route.ts - 0 issues
  • apps/web/src/app/users/after-sign-in/route.test.ts - 0 issues
  • apps/web/src/components/organizations/OrganizationDashboard.tsx - 0 issues
  • apps/web/src/components/organizations/VerifiedDomainsCard.test.ts - 0 issues
  • apps/web/src/components/organizations/VerifiedDomainsCard.tsx - 1 issue
  • apps/web/src/lib/organizations/organizations.ts - 0 issues
  • apps/web/src/lib/organizations/verified-domain-destination.test.ts - 0 issues
  • apps/web/src/lib/organizations/verified-domain-destination.ts - 0 issues
  • apps/web/src/lib/organizations/verified-domain-membership.test.ts - 0 issues
  • apps/web/src/lib/organizations/verified-domain-membership.ts - 0 issues
  • apps/web/src/lib/organizations/verified-domain-service.ts - 0 issues
  • apps/web/src/lib/organizations/verified-domain.test.ts - 0 issues
  • apps/web/src/lib/organizations/verified-domain.ts - 0 issues
  • apps/web/src/lib/user/server-signin-callback.test.ts - 0 issues
  • apps/web/src/lib/user/server.test.ts - 0 issues
  • apps/web/src/lib/user/server.ts - 1 issue
  • apps/web/src/lib/user/sso.test.ts - 0 issues
  • apps/web/src/lib/user/sso.ts - 0 issues
  • apps/web/src/routers/organizations/organization-router.ts - 0 issues
  • apps/web/src/routers/organizations/organization-sso-router.ts - 0 issues
  • apps/web/src/routers/organizations/organization-verified-domains-router.test.ts - 0 issues
  • apps/web/src/routers/organizations/organization-verified-domains-router.ts - 0 issues
  • packages/db/src/migrations/0222_flat_cardiac.sql - 0 issues
  • packages/db/src/migrations/meta/_journal.json - 0 issues
  • packages/db/src/schema-types.ts - 0 issues
  • packages/db/src/schema.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by grok-4.6 · Input: 197.1K · Output: 22.6K · Cached: 878.1K

Review guidance: REVIEW.md from base branch main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant