Skip to content

feat(companies): invite and manage company users - #150

Merged
allisonmahmood merged 4 commits into
mainfrom
auth/146-invite-and-manage-users
Sep 6, 2026
Merged

allisonmahmood merged 4 commits into
mainfrom
auth/146-invite-and-manage-users

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Admins need one place to invite colleagues and manage their access. Members need to see who is in their company without management controls.

Adds /company using the existing server-rendered shell and plain forms. Admins can invite, revoke, resend, change roles, deactivate and reactivate; members get the same read-only list. Clerk sends invitation mail while Patchy owns the invitation, including when delivery fails. The existing transactional last-admin and token-revocation rules protect access changes.

Stacked on auth/138-clerk-sign-in-create-company; this PR targets that branch and contains only the company-management change.

Reactivation restores browser access and permits fresh machine tokens. Previously revoked keys stay revoked, matching the existing Users/glossary contract; #146's “restores both” wording should not imply reviving old credentials.

Closes #146.

Verification: 235 tests passed; pnpm typecheck, pnpm lint, and packed CLI e2e passed. Live development Clerk/browser checks covered invite, resend, revoke, join, last-admin refusals, deactivation/reactivation, CLI access, and mobile layout. An initial unrelated ExpirySweep scheduling failure passed in isolation and on the full rerun. Standards and spec reviews found no implementation issues.

Implemented with OpenAI GPT-6 Astra in the Oh My Pi harness.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:core Touches the core area area:docs Touches the docs area size:l 501-1,000 changed lines labels Sep 5, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed 149d87d against origin/auth/138-clerk-sign-in-create-company (1d02ee9), using #146 and its referenced spec sections. One pass, no subagents; merge blockers only.

Standards

No independent merge-blocking method or YAGNI findings.

Spec

Blocker — intent: resend gets stuck after a remote revoke succeeds but its response is lost

packages/companies/src/Invitations.ts:113–120

#146 asks for “resend as a second create.” Instead, every resend must first successfully revoke the previous Clerk invitation. Any revoke error returns early and retains that invitation's ID.

If Clerk commits the revoke but the response is lost, the next click retries revoking an already-revoked invitation. Clerk only permits active, non-revoked invitations to be revoked. Subsequent resends therefore fail before creating another email; Patchy's invitation remains pending, but its Resend invite control cannot recover. Revoking the link in Clerk's dashboard produces the same mismatch.

Smallest fix: make old-link cleanup idempotent for an already-revoked invitation and proceed to the replacement create, or use the specified second-create flow without making it depend on successful revocation. Keep a focused regression for the lost-response case.

Evidence: an isolated reproduction over migrated Postgres, injecting the remote side effect followed by a transport failure through InviteMail, produced firstResendFailed: true, retryFailed: true, only one delivery, and the original Clerk ID still on the pending row. The 40 existing focused company, invitation, user, and auth-page tests passed. No live Clerk requests were made; the temporary reproduction was kept outside the worktree and removed.

Summary: Standards: 0 blockers. Spec: 1 blocker — resend cannot recover from an already-revoked remote invitation.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Code review: PR 150 vs #146

Two-axis review of 1d02ee9...149d87d (feat(companies): invite and manage company users), plus the method and YAGNI pass you asked for. Six parallel reviewers: Standards, Spec, UI consistency, Effect/surfaces, implementation method, YAGNI.


Intent vs #146

#146 asked for one /company page where an admin invites, revokes, resends, promotes, demotes, deactivates and reactivates, and a member only reads. Clerk sends the mail; Patchy owns the invite row, including when delivery fails. Last admin cannot demote or deactivate themself. Reverse states all live on that page.

That is what landed. Routes, InviteMail (live / recording / failing), Invitations orchestration, glossary, docs/product.md, docs/DEVELOPMENT.md, and the dev-loop skill all follow the ticket. Users.setRole / deactivate / reactivate already existed on the parent branch; this PR sits on them rather than reimplementing them.

The one wording trap is reactivation. #146's tests/done-when say “reactivating restores both” (bearer 401 and the deactivated page). The domain contract is narrower: ADR-0007 “Reactivation restores membership access, not revoked machine tokens”, and the Companies glossary the PR updates. The implementation restores the browser, keeps old keys dead, and allows a fresh mint. The PR body records that reading. That is the parent spec, not a miss of intent.


Standards

Refs: 1d02ee97…149d87d. InviteMail’s three layers, Invitations/CompanyPage as modules, namespace imports, catchTags, it.layer/it.effect, and fault injection via layers match the Effect spec. No ADR conflict.

Hard

packages/auth/src/AuthPages.ts 41–50 — enrolled home lost sign-out. Join still appends signOutForm; company does not:

const company = Effect.fn("AuthPages.company")(function* (action: CompanyPage.Action) {
  const viewer = yield* RequireSession.Viewer;
  const session = yield* Session.Session;
  const page: CompanyPage.Page = yield* CompanyPage.handle(viewer, action);
  return page.redirect
    ? HttpServerResponse.redirect(page.redirect, {
        status: 303,
        headers: { "cache-control": "private, no-store" }
      })
    : pageResponse({ ...page, styles: CompanyPage.styles }, session);
});

Join.handle now always redirects members to /company (packages/companies/src/Join.ts 94, 123). That page has no /logout form. CLAUDE.md hit-every-surface reverse states (way in needs a visible way out). ui-consistency: preserve interaction semantics through a migration; Auth/Companies pages use plain forms. Before this PR, enrolled GET /join was “You are in …” with Sign out. After it, the default logged-in destination has no session way out (Your machines is not in this slice). Fix: append signOutForm() in the company adapter, as join does.

Judgement

packages/auth/src/CompanyPage.test.ts 512–598 — full promote/deactivate/reactivate lifecycle run under both layerRecording and layerFailing though those actions never call InviteMail. CLAUDE.md: tests focused, not slop. One layer is enough.

packages/auth/src/AuthPages.ts 94–104 — shared HttpServerError copy still sends readers to create-or-join, now also covering /company/* POSTs. Update the recovery link or split the helper.

Duplicated Code: InviteMail.ts 21–31 copies Session.ts’s Origin filter. Leave it; extracting would couple Auth to Companies or mint a one-extra-consumer helper.

No other UI-consistency or Effect-service findings.


Spec

(a) Missing or partial. None. /company and the six POSTs match §8; members get the list with no forms; self-deactivate is omitted; last-admin demote/deactivate re-render 409 with the reason. InviteMail has live/recording/failing layers; Clerk ignoreExisting + telemetry off; create-on-Clerk-failure still writes the row with no Clerk id. Users.setRole/deactivate/reactivate exist on the parent and the page uses them (company FOR UPDATE, tokens revoked in the same txn). Tests cover admin vs member, each action on recording and failing mail, HTTP two-admin demote, bearer 401 + deactivated page. /login defaults to /company; enrolled /join GET and successful join go to /company. Glossary, docs/product.md, docs/DEVELOPMENT.md, and patchy-dev-loop are updated.

(b) Scope creep. None of product substance. Extra coverage (cross-company 404, Origin on POSTs, resend/revoke races) follows parent §7 CSRF and company-scoping, not new surfaces.

(c) Implemented but wrong. None.

Reactivation conflict (evaluated, not a defect).
#146 tests: “reactivation reversing both”; done-when: “reactivating restores both” (bearer 401 and deactivated page).
Domain contract: Users.ts “reactivation never revives keys”; glossary Reactivation: “keys revoked by deactivation stay revoked”; ADR-0007: “Reactivation restores membership access, not revoked machine tokens.”
Implementation and tests keep old bearers 401, restore the browser, and allow a fresh mint. PR body states that reading. Faithful to the parent spec; #146’s “both” is loose wording, not a miss.

Also-checks. Removing yourself = deactivate self hidden for every viewer; last-admin demote is shown and refused on submit; last-admin self-deactivate is hidden and still 409 if POSTed. Concurrent demote exists in Users.test.ts (parent) and CompanyPage.test.ts.


Method

The method is the right small one: Auth still only answers who the caller is; Companies owns the tenant, the forms, and Clerk-as-mailman. Routes stay in Auth because that is where the first-party shell and CSRF already sit. The arrow stays Auth → Companies.

/** Auth supplies the viewer; Companies owns the forms and their company-scoped actions. */
export const handle = Effect.fn("CompanyPage.handle")(function* (viewer: Viewer, action: Action) {
  if (action.kind === "view") return yield* render(viewer);
  if (viewer.role !== "admin") {
    return yield* render(viewer, {
      message: "Only an admin can manage this company.",
      status: 403

InviteMail belongs in Companies, not Auth: sessions are identity, invitations are membership. Server-rendered forms, 303, re-render with the reason is the same method as Join, which is the right deployed-stage surface. SPA/JSON would have been a second surface this ticket does not need.

Authorization is enough: viewer is company-scoped, mutations key off viewer.company.id, URL ids are AND company_id = …. Foreign ids 404, members 403 with no mail, missing/wrong Origin 403. Body companyId is ignored.

Last-admin via company-row-then-user lock is the method. Hiding self-deactivate while still showing self-demote is the right product: demote is valid once another admin exists; deactivate-self is a footgun even then. Server still 409s a crafted last-admin POST.

The one overfit is Clerk HTTP inside a Postgres transaction:

// Hold the invite's row lock through delivery and commit. Consumption, revoke and
// resend cannot replace each other's Clerk id; interruption cannot roll back an
// invitation after the external request has already sent its email.
export const create = Effect.fn("Invitations.create")(function* (
  input: Companies.InviteInput
) {
  // ...
  return yield* sql.withTransaction(
    Effect.gen(function* () {
      const invite = yield* companies.createInvite(input);
      return yield* deliver(invite);
    })
  );
}, Effect.uninterruptible);

They already accept Clerk/Patchy divergence on revoke failure, and consumeInvite never reads the Clerk id. Holding a row lock across Clerk HTTP only prevents a leftover email, not a join. Uninterruptible covers interruption, not “Clerk sent, then the UPDATE/commit fails” — that still orphans a live Clerk invitation. Simpler, and still YAGNI: commit the invite, then mail, then store the Clerk id. Same product, no long transaction. Not a spec miss; a smaller model if you touch this again.


YAGNI

Verdict: mostly. Production is the small model. Weight is in the HTTP tests.

Keep InviteMail as a Clerk-shaped service with the three layers the ticket asked for. It is not a generic mail port. Invitations.ts is not a middle-man: the row-lock-through-Clerk constraint does not belong in HTML. Correctly a module, not a service (one production consumer). HTML string soup is house style (Join.ts already). Shared form CSS in html.ts is the right move; page width stays on the page.

No groups, SSO, expiry, webhooks, retry queues, or generic mailer. The lockfile catalogs rewrite is pnpm noise from adding @clerk/backend, not a dep removal.

Cut if you want a smaller diff: the doubled lifecycle under layerFailing (CompanyPage.test.ts 512–598) for actions that never call mail; the 6-action Origin matrix is one sameOrigin middleware; HTTP 502 cases 601–702 re-prove Invitations.test.ts. Distinct HTTP behaviors worth keeping: XSS/escaping, unenrolled door, 422, last-admin, demotion race, bearer after deactivate.


Summary: Standards 1 hard + 2 judgement, worst is /company dropping the enrolled sign-out control. Spec 0 findings; worst within the axis is none (the “restores both” wording is domain-correct, not a miss).

Reviewed with Grok 4.6 in the Grok Build harness; Standards, Spec, UI, Effect/surfaces, method, and YAGNI ran as separate sub-agents.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Addressed both reviews in 1c30c19.

Fixed

  • Resend after a lost revoke response — real blocker. Clerk's 400 invitation_already_revoked now becomes a typed terminal result that revoke/resend treat as completed cleanup. Resend proceeds to its replacement create without changing the Patchy invite ID. Other Clerk/transport failures still report failure; they are not silently treated as successful revocation. Added a regression that performs the remote revoke, loses its response, then retries against the already-revoked state; it also covers local revoke when remote cleanup is already complete.
  • Enrolled sign-out — real blocker. /company now appends the existing plain signOutForm() for admins and members. The socket test discovers and submits that form instead of calling an invisible logout endpoint; both roles' page coverage requires the control.
  • Invalid-form recovery navigation — valid usability finding. The error page links to /company, which returns enrolled users to management and routes unenrolled users through the existing join guard. A body-read failure regression follows the recovery link and verifies no invitation was created.
  • Duplicated lifecycle test — valid simplification. Removed the recording/failing matrix for role and deactivation/reactivation actions. One complete lifecycle runs with mail unavailable, proving these actions do not depend on successful mail.

Kept, with reasons

  • Invite row locks and transaction boundary. These serialize resend/revoke/consume and prevent concurrent actions from overwriting the tracked delivery. Splitting commit/mail/update would need another concurrency policy and cleanup for losing deliveries. That redesign is not needed to fix the reported recovery blocker. This is not a distributed transaction: process/database failure after Clerk sends can still cause divergence.
  • Per-route Origin coverage. Although the middleware is shared, each route is registered separately; the matrix catches an action accidentally registered without protection.
  • HTTP mail-failure coverage. It checks caller-visible status, warning, recovery and join behavior that service-level tests cannot establish.
  • Local Origin validation in Auth and Companies. Kept the small duplication instead of adding cross-capability coupling or a new abstraction.
  • Reactivation leaves old keys revoked. Kept the existing ADR/Users contract: browser access returns and fresh machine tokens work; old credentials are not revived. The reviews agree this is not an implementation defect.

Verification and readiness

  • Regressions failed before the fixes and passed afterward. Local pnpm test: 236 passed; pnpm typecheck, pnpm lint, and packed CLI e2e passed.
  • Live development Clerk/browser verification: created an invite, revoked it directly in Clerk while Patchy retained the ID, then successfully resent from /company with the same Patchy row and a new Clerk delivery. Visually verified and clicked Sign out; landed on /login and confirmed the Clerk session was revoked. Test user/invites were cleaned up, the local seed restored, and the dev instance stopped.
  • Latest commit CI: run 33952268787 passed test (22), test (24), lint (format/lint/typecheck), cli-smoke, dependency-review; the label check also passed. gh pr checks --required reports no separately configured required checks for this PR; all reported checks are successful.
  • Rechecked reviews after the push: no new findings or outstanding formal change requests. GitHub reports MERGEABLE / CLEAN. No unresolved blockers. Ready to merge into the stated stacked base, auth/138-clerk-sign-in-create-company; not merged by this session.

@vsrikar08

vsrikar08 commented Sep 6, 2026 •

Copy link
Copy Markdown
Collaborator
  1. An admin should not be able to make anyone an admin (super admin privilege needed). Out of scope for now but still good to take note of.
  2. Did some tests with daybreak for this. actually good passed the tests from it.
  3. Also, why the fuck does the clerk email expire after 30 days. It should be 24 hours or 7 days at most. set this up.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

@vsrikar08 Following up on your review after discussing it with Allison:

  • Invitation expiry: follow Clerk's policy rather than introduce our own 24-hour or seven-day policy. Clerk documents a 30-day default for application invitations: https://clerk.com/docs/reference/backend/invitations/create-invitation.
  • There is a related implementation gap to address: Patchy's local company invitation currently never expires and can be accepted through create-or-join independently of the emailed link. Keeping Clerk's default alone does not fix that. The follow-up is to make the local invitation respect the corresponding expiry, so the two don't disagree. Allison will take this from here.
  • A super-admin role is outside this change. Keeping the existing member/admin model and admin role-management permissions for this PR.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review of 225975b

Reviewed only 1c30c19..225975b (fix(companies): expire invitations with Clerk's default), in one pass without subagents. Earlier commits were not re-reviewed. Spec: vsrikar08's item 3, as clarified by Allison's September 6 reply.

Standards

No merge-blocking method or YAGNI findings against the repository's Effect/service and UI conventions. The change uses the existing clock, SQL transaction, and migration patterns without adding future-facing machinery.

Spec

No merge-blocking intent findings. Clerk's default remains unchanged; local invitations are filtered from create-or-join and rejected on consumption at expiry. Successful resend renews the deadline, while expired invitations retain their admin resend/revoke controls. Product and domain documentation reflect the change.

Verification: ran pnpm exec vitest run packages/companies/src/Companies.test.ts packages/companies/src/Invitations.test.ts packages/auth/src/CompanyPage.test.ts — 3 files, 33 tests passed, using disposable Postgres. Clerk's documented default was checked; no live Clerk calls were made.

Summary: Standards: 0 blocking findings, worst: none. Spec: 0 blocking findings, worst: none.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

grok review of 225975b

Scoped to 1c30c19..225975b (fix(companies): expire invitations with Clerk's default). The rest of the PR was reviewed earlier and is out of scope.

Spec for this commit is vsrikar08's item 3 (shorten Clerk expiry to 24h/7d) and Allison's 2026-09-06 reply: keep Clerk's documented 30-day default, and make Patchy's local invitation respect that expiry so create-or-join cannot accept after the emailed link is dead.

Standards, Spec, UI, Effect/tests, surfaces, method, and YAGNI ran as separate sub-agents.


Standards

No hard Effect-service or UI-consistency findings.

Companies still follows schemas → tag → make → layer. Invitations stays a module. 0004_invites_expiry is the next global migrator id after auth 0002 and patches 0003. Tests use TestClock. Company page still goes through the auth shell; email is escaped; no new CSS or script.

Judgement — Mysterious Name / vocabulary clash (CompanyPage.ts): the section is still Pending invites / No pending invites., while a row can now read Member · Expired. Glossary and product.md treat expired rows as still pending (live until revoke/consume); the row label uses “Pending” only for unexpired. Smallest fix: rename the section to “Invites”, or keep “pending” in the glossary sense and pick a different row word than “Pending”.

Judgement — Duplicated Code: expiry is expires_at > now in findInvitesByEmail, expiresAt.getTime() <= now in consumeInvite, and the same compare in render. Fine at SQL vs lock vs display; no helper required.

Judgement — Speculative Generality: DateTime.toDateUtc(DateTime.makeUnsafe(now + …)) in Invitations.resend is new Date(now + …) with extra ceremony.


Spec

Quoted:

  • vsrikar08: “why the fuck does the clerk email expire after 30 days. It should be 24 hours or 7 days at most. set this up.”
  • Allison: “follow Clerk's policy rather than introduce our own 24-hour or seven-day policy. Clerk documents a 30-day default” … “make the local invitation respect the corresponding expiry, so the two don't disagree.” The gap: the local invite “never expires and can be accepted through create-or-join independently of the emailed link.”

(a) Missing / partial. Core gap is closed: findInvitesByEmail drops expired rows, consumeInvite refuses them, join cannot accept after local expiry. vsrikar's 24h/7d is correctly not implemented.

Partial on “so the two don't disagree.” Local expires_at = now + INVITATION_LIFETIME_MS. InviteMail.create still omits expiresInDays and does not bind to a Clerk timestamp (the documented Invitation type has status including "expired", not expiresAt). Same documented default, two independent clocks. Insert sets local expiry before the Clerk create, so Patchy can expire slightly earlier (safer). If Clerk later changes the default, they diverge again — the disagreement this follow-up named.

(b) Not asked; inferred product. Expired rows keep the unique pending (company, email) slot; /company still lists them as Expired with Resend/Revoke; resend renews another 30 days; docs/CONTEXT say so. Necessary reverse-state, not a miss, but it is more than the comments wrote down.

(c) Fragile, not wrong. A parallel 30-day constant is a reasonable reading of “Clerk's default,” not a strong guarantee they never disagree. Passing expiresInDays: 30 would pin the pairing without changing policy.


Method

The method is the right small one. A stored expires_at is required: resend must renew without lying about created_at. Deriving created_at + 30 cannot do that. Persisting Clerk's expiry is not available on the documented Invitation object, and a failed mail create has no Clerk row.

Check sites are coherent:

  • join listing: SQL in findInvitesByEmail
  • consume: JS after FOR UPDATE
  • admin UI: label only; listInvites keeps expired

Expired still occupying the unique slot is the unsurprising occupancy: one live row, resend or revoke. Freeing the slot on expiry would race a second invite.

InviteMail unchanged is correct for the local-expiry feature. The only method gap is duration pinned by assumption: the smallest pin, if you want the two clocks contracted rather than documented, is expiresInDays: 30 on createInvitation.

deliver(invite, expiresAt) rewriting expires_at on create (already set by INSERT) is a harmless conflation of “attach Clerk id” and “renew”. DateTime.makeUnsafe on resend is style noise next to millis/to_timestamp in Companies.ts. Migration importing INVITATION_LIFETIME_MS from Companies.js couples Migrator SQL to the service module; interval '30 days' is a frozen backfill and the constant can stay for runtime writes.

Would change only if shipping again: freeze the backfill as interval '30 days'; optionally pass expiresInDays: 30; new Date(now + INVITATION_LIFETIME_MS) on resend.


YAGNI

Verdict: mostly. Production is the small model. expires_at is not speculative; resend cannot be expressed as created_at + 30d. Constant + Clerk docs link should stay — that is the non-obvious “why 30.” Tests are focused (join/consume hide+refuse, resend renews, page shows Expired with controls; 31d → 29d tweak is intentional). Expiry checks duplicated across SQL/JS/render should stay duplicated. No extra types or hooks.

Cut if you want a smaller diff: the expiresAt argument on deliver (create rewrites the INSERT); the one-site DateTime import.


Surfaces

Wire, CLI, and seed did not apply (Invite is not on the HTTP JSON API; no seed invite rows). Vocabulary (product.md, CONTEXT.md), migration 0004 (already composed by server / dev / vitest), and reverse states (Expired visible, resend renews, revoke remains) are hit.

Half-hit: create-or-join hides expired invites through findInvitesByEmail, covered at the service layer, but AuthPages.test.ts has no /join GET/POST case for an expired invite. /company did get the HTTP case.

Also untested, load-bearing: second invite while expired → AlreadyInvited (unique index should do it); resend with mail failure leaves expires_at unchanged.

No UI-consistency findings.


Summary: Standards 0 hard + 3 judgement, worst is /company heading still saying “Pending invites” over Expired rows. Spec 1 partial, worst is duration mirrored from Clerk's docs rather than pinned, so the two clocks can still disagree if Clerk's default moves. Method/YAGNI: right small model; optional expiresInDays: 30 is the only change that would make “don't disagree” a contract.

Reviewed with Grok 4.6 in the Grok Build harness; Standards, Spec, UI, Effect/tests, surfaces, method, and YAGNI ran as separate sub-agents.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review resolution — e64e93a

Reviewed both Astra review of 225975b and grok review of 225975b against the source and the pre-decided expiry design. Astra reported no blockers; Grok's actionable points were migration immutability and two coverage gaps.

Fixed

  • Freeze the historical backfill: migration 0004_invites_expiry no longer imports the runtime lifetime constant from Companies. Its backfill is fixed at interval '720 hours': exactly the original 30-day policy, without daylight-saving shifts. A future runtime-policy change cannot silently change a fresh database's historical migration.
  • Expired-row uniqueness coverage: extended the existing expired-invite test to prove another create returns AlreadyInvited; the stale row remains visible for resend/revoke.
  • Failed-resend coverage: advanced TestClock in the existing revoke-failure test, whose unchanged-row assertion now detects accidental renewal. Extended the replacement-delivery-failure test past expiry: the stored deadline is unchanged, the invitation stays hidden from join lookup, and a successful retry makes it joinable again. No new test matrix.

Kept as is, with reasons

  • Clerk default / independent timestamps: no expiresInDays override. The approved task explicitly says to keep Clerk's default and compute local expiry at create/resend time, with one documented runtime constant. Explicitly pinning Clerk would replace that default rather than follow it. Local time is captured before the remote create, so this is conservative rather than an extension of an expired emailed link; it is not a claim of timestamp identity. A future Clerk default change will require updating the documented local mirror.
  • “Pending invites” heading: pending means unresolved (neither consumed nor revoked), including expired rows that still occupy the unique slot. The glossary/product contract says this explicitly; each expired row is separately labeled “Expired.” Retained the agreed minimal UI rather than rename its vocabulary.
  • Separate expiry comparisons: SQL filters join candidates, the post-lock check guards consumption, and rendering labels admin-visible rows. Their different boundaries justify the small repeated comparison; a helper would not remove the SQL predicate.
  • DateTime conversion: retained. The repo's Effect diagnostics reject new Date inside Effect code (globalDateInEffect), so the proposed simplification would break typecheck.
  • deliver(invite, expiresAt): retained the shared successful-delivery update. Create preserves its original deadline; resend supplies a new one; failed delivery changes neither deadline. Splitting this would add paths without correcting behavior.
  • No extra /join HTTP expiry case: retained the expressly requested service seam for hidden lookup + rejected consumption, plus the existing HTTP routing coverage. /join GET uses findInvitesByEmail, and POST uses consumeInvite and handles InviteUnavailable; there is no alternate acceptance path. The company-page HTTP test already covers Expired with Resend/Revoke.
  • Expired slot/listing/resend renewal: these were explicit requirements in the implementation request, not inferred product scope. Kept the reverse states. No wire/CLI/seed changes are needed; no invitation JSON contract or seed invitation rows changed, and all three migration runners already compose the Companies migration record.

Verification

  • pnpm exec vitest run packages/companies packages/auth: 10 files, 91 tests passed.
  • pnpm lint and pnpm typecheck: passed.
  • pnpm test: 33 files, 239 tests passed.
  • Disposable-Postgres smoke: a historical 2026-02-15T17:00:00Z invitation migrated under America/New_York to 2026-03-17T17:00:00Z — exactly 2,592,000 seconds, across DST. Temporary driver/database removed. No live Clerk calls or production changes.

Merge readiness

Latest PR head: e64e93a3427ea280154ef78a75e01995dc7c32f9 (pushed).

CI run 34033492672 is successful on that head: test (22), test (24), lint (including format/typecheck), cli-smoke, and dependency-review all passed. The separate label check also passed. GitHub reports no configured required checks for this branch (and no effective base-branch rules); all configured checks were nevertheless verified green.

PR is MERGEABLE / CLEAN, with no new review comments after the push and no inline review comments. No unresolved blockers. Ready to merge into the existing PR base; not merged.

Implemented and verified with GPT-6 Astra in Oh My Pi.

@allisonmahmood
allisonmahmood force-pushed the auth/138-clerk-sign-in-create-company branch from 1d02ee9 to 266e5ce Compare September 6, 2026 12:47
Base automatically changed from auth/138-clerk-sign-in-create-company to main September 6, 2026 12:51
Implement #146 with server-rendered company management, Clerk invitation delivery, and lifecycle coverage. Reactivation restores browser access while revoked machine tokens remain dead.
Handle Clerk already-revoked invitations as completed cleanup after a lost response. Restore sign-out on the company page, fix form recovery navigation, and remove duplicate lifecycle coverage.
@allisonmahmood
allisonmahmood force-pushed the auth/146-invite-and-manage-users branch from e64e93a to 59dfead Compare September 6, 2026 12:51
@allisonmahmood
allisonmahmood merged commit 4919031 into main Sep 6, 2026
6 checks passed
@allisonmahmood
allisonmahmood deleted the auth/146-invite-and-manage-users branch September 6, 2026 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:core Touches the core area area:docs Touches the docs area area:server Touches the server area size:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(companies): invite and manage the company's users

2 participants