Repository navigation
Description
Parent
Auth: Clerk, companies and machine tokens on tier 0, spec §8 and §11.
What to build
An admin runs the company from one page. /company lists users with roles and state and the pending invites; an admin invites an email with a role (Clerk sends the mail, Patchy owns the row), revokes or resends an invite, promotes, demotes, deactivates and reactivates; a member reads the same page with no actions. Deactivation ends the user's sign-in and machine tokens in one act; reactivation is on the same page. The last admin can neither demote nor deactivate themself.
Do
/company(Companies, behindRequireSession) and its sixPOSTactions exactly as spec §8:POST /company/invites(email, role),POST /company/invites/:id/revoke,POST /company/invites/:id/resend,POST /company/users/:id/role,POST /company/users/:id/deactivate,POST /company/users/:id/reactivate; admin only, 303 back to/company; members see the list without actions; removing yourself is not offered; the last-admin refusals re-render with the reason./login's default return and/join's "already in a company" destination become/company.InviteMailin Companies over Clerk'sPOST /v1/invitations(ignore_existing), revoke, and resend as a second create: a live layer, a recording layer and a failing layer. A Clerk failure still writes the invite row with no Clerk id and tells the admin the email did not go out. An email already on a user row is refused with already in a company; a second live invite for the same email from the same company is refused, from another company allowed (spec §3).Usersgains what the page needs:setRolewith the last-admin rule under a row lock,deactivaterevoking every machine token of the user in the same transaction,reactivate.- Tests: the page for an admin and a member; each action through the recording and failing
InviteMaillayers; the last-admin rule, including two admins demoting each other at once leaving at least one admin; deactivation making the user's bearer a 401 and their next page load the deactivated page; reactivation reversing both. - Glossary: Companies' Invite (Clerk sends, Patchy owns, no expiry, revoke and resend, several companies may invite one address), Deactivation and Reactivation, Admin and Member say what is in code.
docs/DEVELOPMENT.mdnotes that inviting on a dev instance sends real mail through the developer's Clerk application.
Surfaces
Served pages (ui-consistency); vocabulary and product shape; reverse states (invite and revoke, promote and demote, deactivate and reactivate, all on one page).
Done when
- On a
pnpm devinstance signed in as Patchy Dev's admin: inviting an address creates a Clerk invitation (visible in the dashboard) and a row; revoke clears both; a second sign-in with the invited+clerk_testaddress lands on/joinwith the invite and joins. - Deactivating that user makes
pnpm patchy whoamiwith their token a 401 and their browser a deactivated page; reactivating restores both. - The last admin's demote and deactivate buttons are refused with the reason.
-
pnpm test,pnpm typecheck,pnpm lintand the packed e2e pass.
Decisions implemented
Company and user; Clerk Organizations as the company (invitations); The dev loop and tests with Clerk (InviteMail's three layers); spec §3, §8, §11.
Activity
feat(companies): invite and manage company users
feat(companies): invite and manage company users