Skip to content

Let people join organizations through their company email domain - #300

Merged
tnkuehne merged 6 commits into
mainfrom
domain-join
Nov 23, 2026
Merged

tnkuehne merged 6 commits into
mainfrom
domain-join

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

People at a company can now join its organization without an invitation. An organization opens itself to a company email domain, and everyone with a verified address on that domain sees it on the organization chooser and joins as a member.

Changes

  • Proof that a company owns the domain. Only someone whose own sign-in proves the domain can open an organization to it: a linked Google Workspace account whose saved ID token names the domain as hd, or a Microsoft work account with xms_edov outside the consumer tenant. Better Auth saves these tokens at every sign-in, so no extra claim storage is needed. An email code proves only a mailbox, so mail-provider domains never qualify.
  • Creation. The create form offers "Enable access for example.com", on by default, when the creator's sign-in proves the domain. createOrganization extensions still receive only name and slug.
  • Members settings. Owners and admins see "Join by email domain": the open domains, removal, and a button for the domain their own sign-in proves. Removing a domain keeps everyone who already joined. Changes apply optimistically and roll back on failure.
  • Joining. The chooser lists organizations open to the person's verified domain with one colleague from the same domain (never external guests) and the number of other members, and a verified mark when the organization verified that domain by DNS for company SSO. Joining checks the domain again and adds the member under the settings lock that removing a join domain takes, so a removal either ends the join or follows it; the 100-member limit is checked under the same lock. A company sign-in limited to its organization by companySignInLimit joins nothing else, and organizations the installation disables stay hidden.
  • Reserving new organizations. An organization that verified a domain by DNS can turn on "Reserve new organizations for administrators". People on that domain who are not its owners or admins can then neither create organizations nor open another organization to the domain. Existing organizations and their join domains continue unchanged.
  • Storage. organization_settings gains join_domains (jsonb, default []) and restrict_organization_creation (boolean, default false), next to sso_required (migration 0038).
  • API and CLI. GET /organizations/joinable, POST /organizations/{organizationId}/join, GET /settings/domain-access, POST /settings/join-domains, DELETE /settings/join-domains/{domain}, PUT /settings/organization-creation and allowDomainJoin on POST /organizations. The CLI adds organizations joinable, organizations join ID, organizations create --allow-domain-join and settings domain-access, add-join-domain, remove-join-domain and restrict-organization-creation.
  • Organization chooser. The chooser uses the sign-in page's card: 44 px fields, dark primary buttons and a footer strip for signing out. Creating asks for a name and a URL; the URL shows the installation's host and follows the name until it is edited. Subtitles that repeated the heading are gone.
  • Only installations with self-service organization creation expose joining; elsewhere the endpoints return 403 and the settings section stays hidden.

Screenshots

Synthetic fixtures, rendered from main and this branch.

A new colleague joins

View Before After
1280 px, light
1280 px, dark
390 px, light
390 px, dark

The domain is verified by DNS for company SSO

View After
1280 px, light
1280 px, dark
390 px, light
390 px, dark

Creating an organization with a Google Workspace sign-in

View Before After
1280 px, light
1280 px, dark
390 px, light
390 px, dark

Creating an organization from the join view

View After
1280 px, light
1280 px, dark
390 px, light
390 px, dark

Choosing among existing organizations

View After
1280 px, light
1280 px, dark
390 px, light
390 px, dark

Members settings

View Before After
1280 px, light
1280 px, dark
390 px, light
390 px, dark

Checked: joining, creating with and without the domain switch, the verified mark, the way back from the create form, choosing an existing organization and the Members section, each at 390 and 1280 px in light and dark.

Not checked visually: the chooser for people who already have organizations and also see joinable ones under "Open to example.com", the error feedback in the Members section, and the message shown to blocked creators.

Validation

  • provider-email-domain.test.ts: Google hd match, mismatch, missing and unverified email, a Gmail-style account, Microsoft work tenant with true and "1", consumer tenant with "1", xms_edov false, missing and other values, missing tenant, malformed tokens and other providers.
  • domain-access.integration.test.ts: creation with and without proof (email code only, consumer tenant, personal Google account, unverified address), joining (allowed, other domain, unverified email, external guest in a company sign-in, disabled organization, member limit), colleague names and the Verified label, administrator settings through the API (unproven and foreign domains, member access, reservation without verified domain, removal keeping members) and the creation reservation (blocked creators, blocked domain opening, administrators of the reserving organization, existing join domains kept).
  • domain-access-migration.integration.test.ts: existing settings rows receive the closed defaults.
  • cli.test.ts: the new CLI commands and request bodies against the synthetic API.
  • New browser test domain-join.spec.ts: a colleague joins by email code, an administrator removes and restores the join domain, and a creator opens a new organization to the domain.
  • Full Vitest suite: 1266 passed. Browser suites auth, onboarding, public-onboarding, oidc, organization-writes, self-hosted-sso, setup and domain-join: all passed. cargo clippy and cargo test -p platform-cli pass. Control-plane typecheck, format and type-aware lint are clean.
  • Not verified with a real tenant: whether Microsoft sends xms_edov for a Gmail guest in a work tenant. The browser and integration tests use synthetic ID tokens.

Documentation: #301 (draft, waits for a release that includes this change).

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new blocking issues were found.

Summary

Adds joining organizations by verified email domain, administrator controls, creation restrictions, and API and CLI commands.

  • People with a verified company email can join organizations that open access to their domain.
  • Organization admins can manage which company domains may join and reserve new organizations.
  • Organization creators can open their new organization to colleagues on their company domain.

Reviews (7) · Last reviewed commit: "Return to the organization choices after..." · Reviewed by Greptile

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 8a67c2b Nov 23 2026, 09:15 AM

Organizations on installations with self-service creation can now open
themselves to a company email domain. People with a verified address on
that domain see the organization on the chooser and join it as members
without an invitation.

- A domain can be opened only by someone whose own sign-in proves that a
  company owns it: a linked Google Workspace account whose ID token names
  the domain as `hd`, or a Microsoft work account with `xms_edov` outside
  the consumer tenant. Better Auth saves these tokens at every sign-in.
  Email codes prove only a mailbox, so mail-provider domains never qualify.
- Creation offers "Allow anyone with a @Domain address to join", on by
  default when the creator's sign-in proves the domain. Owners and admins
  add or remove proven domains under Members. Removing a domain keeps
  existing members.
- The chooser lists joinable organizations with their member count, up
  to three colleagues from the same domain and a Verified label when the
  organization verified the domain by DNS for company SSO. Joining uses
  Better Auth's member limit. Company sign-ins that are limited to their
  organization join nothing else, and disabled organizations stay hidden.
- An organization that verified a domain by DNS can reserve new
  organizations on it for its owners and admins. Others with that domain
  can then neither create organizations nor open another organization to
  it. Existing organizations and their join domains continue unchanged.
- `organization_settings` gains `join_domains` and
  `restrict_organization_creation`, next to `sso_required`.
- The same operations are available through the API
  (`/organizations/joinable`, `/organizations/{id}/join`,
  `/settings/domain-access`, `/settings/join-domains`,
  `/settings/organization-creation`, `allowDomainJoin` on creation) and
  the CLI (`organizations joinable|join`, `organizations create
  --allow-domain-join`, `settings domain-access|add-join-domain|
  remove-join-domain|restrict-organization-creation`).
…re joining is off

Domain access controls stay disabled while a change is saving, so a
second click cannot overtake the first. The joinable list now answers
403 on installations without self-service organizations, like the
other domain access operations; the chooser skips it there.
The chooser now uses the sign-in page's card: a footer strip with the
signed-in address and sign-out, 44 px fields and dark primary buttons.

- Creating an organization asks for a name and a URL. The URL shows the
  installation's host as a prefix and follows the name until it is
  edited.
- The domain switch reads "Enable access for example.com" on one line.
- Joinable organizations show an initial, the Verified label, two
  colleagues and how many others belong to it.
- Creating an organization from the join or choose view opens the form
  with a way back.
- Joinable organizations show a verified mark beside the name and one
  line naming a colleague and how many others belong, so the row no
  longer crowds the Join button.
- Headings stand alone where a subtitle only repeated them, and the
  create form no longer promises invitations next to the domain switch.
- The footer strip only offers signing out.
A join checked the join domain and then added the member through a
separate Better Auth call. Removing the domain in between could finish
first, and the person still became a member.

Joining now takes the organization's settings lock that removing a join
domain takes, checks the domain again and inserts the member in the same
transaction. A removal either ends the join or follows the new
membership, which it keeps like any earlier one. The member limit is
checked under the same lock and shared with Better Auth through
organizationMemberLimit.
A failed creation kept the form open through its issues, so Back did
nothing and the existing and joinable organizations stayed hidden. Back
now always returns to the choices; without choices, the form still stays
to show why creation failed.
@tnkuehne
tnkuehne merged commit 694b5a2 into main Nov 23, 2026
15 of 16 checks passed
@tnkuehne
tnkuehne deleted the domain-join branch November 23, 2026 09:21
tnkuehne added a commit that referenced this pull request Nov 23, 2026
## Problem

An organization with company SSO proves its email domains through DNS.
Since #291, its SSO session also reaches the person's other memberships
for an address on those domains. The company still did not own sign-in
for these addresses:

- An email code sent through an organization link or the API signed them
in.
- Google and Microsoft signed them in.

The resulting personal session reached every membership without passing
the company's sign-in. Required SSO protected only the organization
itself.

## Change

Organizations with active company SSO now own sign-in for their verified
domains, as WorkOS domain policies do.

**Setting**
- New column `organization_settings.domain_sso_required` (migration
`0040_domain_sso`).
- Activating company SSO turns it on; removing the connection turns it
off. The migration copies `sso_required`, so organizations that already
require SSO keep that requirement for their domains.
- Administrators switch it on the **Company sign-in** page, with `PUT
/api/v1/settings/domain-sso` or with `widefleet settings domain-sso
true|false`. Turning it on requires active SSO and a verified domain.
`GET /settings` adds `domainSsoRequired`.
- The rule applies only to DNS-verified domains of an organization the
installation admits. An operator-trusted provider without DNS proof does
not claim addresses.

**Enforcement**
- **Session creation** rejects a personal session for such an address
with `COMPANY_SSO_REQUIRED` and the provider ID. Every personal sign-in
method passes this check. Company SSO, another organization's SSO for a
guest, and recovery stay available.
- **Email codes:** `send-verification-otp` and `sign-in/email-otp`
return the same error, so no code is sent. The sign-in form continues
with company SSO, as the email field already does.
- **Google and Microsoft:** `validateUserInfo` rejects the address
before any user, account or session is created. The callback returns to
`/sign-in/connect` with `error=company_sso_required` and an encrypted,
10-minute hint (`symmetricEncodeJWT` with the auth secret). The page
decrypts it and starts company SSO with the address as login hint and
the original `next`, so OAuth and device continuations survive. A loop
guard falls back to a button.
- **One organization per domain:** verifying a domain that another
organization has already verified fails with a conflict. Earlier,
organizations that controlled the same DNS could both verify a domain;
that was kept in #204 to avoid a failing unique-index migration. The
check runs at verification and needs no index. With shared domains, an
address would have had two company sign-ins.
- Existing sessions and CLI grants stay valid until they end.
- **Joining by email domain (#300):** these addresses can no longer
prove their domain through Google or Microsoft. A linked company SSO
account of the organization that verified the domain by DNS now proves
it instead, so its administrators can still open organizations to the
domain.

**UI**
- New section **Company addresses use SSO only** with a switch on the
Company sign-in page. The switch is optimistic: a failed change returns
to the previous state and explains why in a toast. The shared `Toaster`
and `toast` export are the same lines as in #288.
- `/sign-in/connect` gets a **Continue with company SSO** state.

## Tests

- `social-sign-in.test.ts`:
- Google and Microsoft, for existing and new users, return the encrypted
hint without the address in the URL and create nothing.
  - Email code send and verify return `COMPANY_SSO_REQUIRED`.
- `organization-sso.integration.test.ts`:
  - A personal session is rejected.
  - An address on another domain still signs in.
  - Company SSO, another organization's SSO and recovery still work.
- A non-admitted organization, inactive SSO and a disabled rule each
lift the requirement.
- `organization-settings.integration.test.ts`:
- Activation turns the rule on and administrators can turn it off and on
again.
  - Removing SSO clears it; enabling without SSO conflicts.
- `company-sso-plugin.integration.test.ts`:
  - Activation through settings enables the rule.
  - A domain verified by another organization is rejected.
- `cli.test.ts`: `settings domain-sso`.
- **Local runs:**
  - `vitest run`: 1255 passed, 667 skipped.
  - `RUN_CLI_TESTS=1` CLI tests: 60 passed.
  - Control-plane `svelte-check`, oxlint and oxfmt on the changed files.
  - `cargo fmt --check` and `cargo clippy -p platform-cli -D warnings`.
- Playwright E2E was not run locally; CI covers it.

## Visual review

Goal: administrators see which addresses the rule covers and can switch
it. A person who picks Google is taken to their company's sign-in.

Checked at 1280 and 390 px in light and dark themes, rendered with the
built server and synthetic fixtures. No horizontal overflow, the switch
stays aligned with the title at 390 px, and the domain list wraps.

**Company sign-in, before → after (1280, light)**

| Before | After |
| --- | --- |
| <img width="420"
src="https://gist.githubusercontent.com/tnkuehne/ee0d49f9b80b16f92500a55f2e180ccd/raw/20afa5d25570a5f6b2f7301c306a5a72b4e7a031/before-sso-1280-light.png">
| <img width="420"
src="https://gist.githubusercontent.com/tnkuehne/ee0d49f9b80b16f92500a55f2e180ccd/raw/20afa5d25570a5f6b2f7301c306a5a72b4e7a031/after-sso-1280-light.png">
|

**Switched off at once (390, dark) and narrow layout (390, light)**

| Off (optimistic) | On |
| --- | --- |
| <img width="300"
src="https://gist.githubusercontent.com/tnkuehne/ee0d49f9b80b16f92500a55f2e180ccd/raw/20afa5d25570a5f6b2f7301c306a5a72b4e7a031/after-sso-off-390-dark.png">
| <img width="300"
src="https://gist.githubusercontent.com/tnkuehne/ee0d49f9b80b16f92500a55f2e180ccd/raw/20afa5d25570a5f6b2f7301c306a5a72b4e7a031/after-sso-390-light.png">
|

**Google or Microsoft with a company address**: shown only when the
automatic start is skipped by the loop guard; otherwise the browser goes
straight to company SSO.

| 390, light | 1280, dark |
| --- | --- |
| <img width="300"
src="https://gist.githubusercontent.com/tnkuehne/ee0d49f9b80b16f92500a55f2e180ccd/raw/20afa5d25570a5f6b2f7301c306a5a72b4e7a031/after-connect-390-light.png">
| <img width="420"
src="https://gist.githubusercontent.com/tnkuehne/ee0d49f9b80b16f92500a55f2e180ccd/raw/20afa5d25570a5f6b2f7301c306a5a72b4e7a031/after-connect-1280-dark.png">
|

Not checked visually: the toast after a failed switch (same component
and pattern as #288), and the expired-hint state, which shows the text
without the button.

Documentation: #307 (draft until a release includes this change).
















<!-- greptile_comment -->

<!-- greptile_summary -->

<h2><a
href="https://app.greptile.com/api/retrigger?id=115870316&amp;sig=775908ce03283199d8ab76b3b29d4e0b6b28c1a226cf27f9b5ecb19862b1fdfb"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img
alt="Retrigger"
src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"
align="right"></picture></a><a
href="https://app.greptile.com/-/switch-tenant?tenant=mendra&amp;next=%2Fwidefleet%2Fwidefleet%2Fpull%2F306&amp;utm_source=greptile_review&amp;utm_medium=github&amp;utm_campaign=view_in_greptile"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img
alt="View in Greptile"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"
align="right"></picture></a>Confidence Score: 5/5 <sup><img alt="Tier:
apex" title="Review tier: apex"
src="https://greptile-static-assets.s3.amazonaws.com/badges/effort-apex.svg?v=3"
height="12"></sup></h2>

<!-- greptile-impact-verdict --> The PR appears safe to merge with
#307’s immediate switch handler included.

<details open><summary><h3>Summary</h3></summary>

Requires company SSO when a personal sign-in uses an address on an
admitted organization’s verified domains.

- Administrators can require company SSO for addresses on verified
domains.
- Personal sign-ins with covered addresses continue through company SSO.
- Each DNS-verified company domain belongs to one organization.
- Linked company SSO can prove its verified domain for organization
joining.

Tests and browser checks were not rerun.
</details>

<details open><summary><h3>Diagram</h3></summary>

```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Email code, Google, or Microsoft"] --> B{"Company SSO required for this domain?"}
  B -->|No| C["Create personal session"]
  B -->|Yes| D["Continue with company SSO"]
  D --> E["Create company session"]
  F["Other organization SSO or recovery"] --> E
  G["Other personal sign-in methods"] --> H["Check domain rule before creating session"]
  H --> B
```
</details>

<!-- greptile_confidence_score:5 -->

<sub>Reviews (8) · Last reviewed commit: ["Accept company SSO on a
verified domain
..."](e687348)
· [Reviewed by
Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub>

<!-- /greptile_comment -->
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