Repository navigation
feat(email)!: invite a manager to what they are assigned, and let a reminder sign them in - #853
Conversation
A newly created manager received Payload's generic "verify your email" and learned nothing about what they had been given — and the link in it addressed `/admin/managers/verify/:token`, a form that asks for a password this flow never sets. `auth.verify` stays configured, because it is what creates the `_verified` column and the JWT strategy yields no user while that column is false. So `_verified` is the accepted/not-accepted flag the whole flow turns on. Only the two generators move, to `inviteVerification`, which ignores the framework's token and mints a `manager-invite` one instead — a separate audience from a sign-in link, so neither route can spend the other's. The invitation composes from `roles` and `type` alone. `managedPages`, `managedRegions` and `managedEvents` are join fields, so nothing points at a manager created one instant ago and all three read empty; a resend, sent later, could name them. Reading roles per locale happens inside the create's own open transaction, so `summarizeGrants` passes `localeIsolatedReq(req)` — without it `createLocalReq` repoints the caller and the create's localized write lands at `all` (#609). Nothing in either generator may throw: `sendVerificationEmail` is awaited before `commitTransaction` and outside any `try`. Accepting is `POST /api/<slug>/redeem-invite`, a sibling of the sign-in burn behind the same confirmation form, so a mail scanner's GET still spends nothing. `_verified` is what makes an invitation single-use, since a token minted during `create` has no timestamp to match against. `issueMagicLink` picks between the two on the same flag: an unaccepted manager asking for a link is re-sent their invitation. That is the self-service rescue for a manager nothing else would ever mail — an imported row, or a lost invitation — and it is why #680 no longer needs a DB edit. Refs #839, #664 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TuFkXDLHXTjGtocMRwZcLb
The importer copied the legacy `emailVerified` flag into `_verified`, which marked a manager as having accepted an invitation nobody ever sent them — the opt-out beside it (`disableVerificationEmail: true`, for mail rate limits) stays. An imported manager now arrives unaccepted, and the magic link is their way in: `isEligible` reads `type` only, so they may request one, and an unaccepted account is sent the invitation rather than a sign-in link. Redeeming sets `_verified` itself. `emailVerified` stays readable under `legacyData`. Refs #839 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TuFkXDLHXTjGtocMRwZcLb
`manager-invite.spec.ts` is the unit half: the grant summary, and the URL and token audience `Managers.auth.verify` actually builds. Both regression assertions were watched failing against the real defects — passing `req` straight through repoints the caller's locale, and signing the sign-in audience makes the invitation spendable as a sign-in link. `manager-invite.int.spec.ts` is what only a booted Payload can show: that a create sends exactly one email, that the localized write still lands where the create asked, that accepting flips `_verified` and mints a session, and that the second click is refused. The link is read out of the captured email, so a template embedding no link at all would fail here. Two existing specs move with the behaviour. `manager-auth-urls.spec.ts` keeps only the reset shape, since `auth.verify` no longer builds an admin URL. `manager-magic-link.int.spec.ts` mints its unverified-manager token directly: asking for a link now sends that manager the invitation instead, so the sign-in route's own handling of an unaccepted account is only reachable from a link issued before the flag was cleared. Refs #839 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TuFkXDLHXTjGtocMRwZcLb
…ation `manager-verification.int.spec.ts` tested a loop that no longer exists: no email carries `/admin/managers/verify/:token` any more. The one property it held alone — password login refused by NAME while unaccepted, and allowed after — moves into `manager-invite.int.spec.ts`, asserted against the real accept route rather than `payload.verifyEmail`. Refs #839 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TuFkXDLHXTjGtocMRwZcLb
The four existing `preview-*-emails` scripts cover registrant and event mail. Nothing rendered a manager auth email, so the invitation's grant rows — the part a reviewer most needs to see — had no way to be looked at. It drives `inviteVerification`, the object `Managers.auth.verify` installs, so the subject, the URL shape and the rows are the ones a create sends. The `payload` stub covers the two calls that path makes: the `locale: 'all'` roles read, and `secret`. Refs #839 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TuFkXDLHXTjGtocMRwZcLb
`issueMagicLink`'s select had grown `type`, which is a `managers` enum and means nothing to another auth collection — `config.select` is where a collection names its own fields, and `managersLogin` already lists it. `_verified` stays in the generic list because it is the opposite case: it exists on every auth collection, `verify` configured or not, which is what lets the branch below read it whatever is served. Refs #839 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TuFkXDLHXTjGtocMRwZcLb
Three holes a review pass found, each latent but each cheap to shut: **An account created already accepted was still invited.** Payload gates the send on `result.email` alone, never on `_verified`, so `seedPreviewAdmin` mailed every fresh Railway preview an invitation that `redeem-invite` refused the instant it was clicked. It now opts out, which is what a seeded, already-active account wants anyway. **`_verified` is not a column every auth collection has.** `getAuthFields.js` adds the verification fields only for a collection configuring `auth.verify`, so the resend branch would read `undefined` on one that does not and send it an invitation forever, never a sign-in link. The branch now asks Payload's own sanitized config whether there is an accepted flag to read. **`summarizeGrants` reads `managers` by id.** Reached from generic plugin code it would name a stranger's roles — or throw `NotFound` inside the create's open transaction, which costs the whole account. It now returns an empty summary for any other collection rather than reading. Three assertions go with them. The sign-in page's two redeem URLs move into `urls.ts` and are pinned: nothing rendered that page, and an invitation posted to the sign-in route is refused for a wrong audience, which reads as "this link is not valid" while both lanes stay green. `invite-expired` is now reached. And two template assertions that could not fail are replaced by the one that can — the summary reads `roles` and nothing else, which is where "names no region or page" actually lives. Refs #839 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TuFkXDLHXTjGtocMRwZcLb
…old mail `docs/rules/email.md` gains the invitation, what `auth.verify` is now kept for, and the two traps around `_verified` — that a create setting it itself must also opt out of the send, and that it is not a column every auth collection has. The verify-URL table stays as the routing lesson it always was, marked as history. `src/AGENTS.md` and `docs/rules/endpoints.md` counted the login plugin's endpoints; there are three. `docs/rules/access.md` named the one route that mints a session and redirects rather than returning a user; there are two. Refs #839 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TuFkXDLHXTjGtocMRwZcLb
…er-invitation-email # Conflicts: # src/collections/Managers/Managers.ts
|
🚅 Deployed to the SahajCloud-pr-853 environment in sahajcloud
1 service not affected by this PR
|
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff tracks a large ticket honestly. Every file maps to a stated acceptance criterion, VerifyEmail leaves with all three consumers, and the transaction hazard #839 named is handled the way it asked. One place is bigger than the problem: redeemInvite.ts is redeemMagicLink.ts copied, where one parameterised factory would keep both audiences. No cross-repo surface moves.
Findings
- should-fix — a second redeem handler copied rather than shared (
redeemInvite.ts:73) - should-fix — the diff contradicts a comment it leaves standing (
magicLinks.ts:149) - consider —
emailFromhanded three fields it never reads, one misnamed (magicLinks.ts:158) - consider — one page's copy in two homes (
ConfirmSignIn.tsx:25)
What was checked
Read whole: invite.ts, grantSummary.ts, both redeem endpoints, magicLinks.ts, mail.ts, InviteEmail.tsx, the four signin/ files, Managers/login.ts, localizedRoles.ts. normalizeLocalizedRoles drops empty locales, so no blank grant row renders.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`redeemInvite` was `redeemMagicLink` copied: the refusals, the eligibility re-check, the burn, the cookie and the 302 were identical, down to the `joins: false as never` cast and a second `DEFAULT_REDIRECT`. The landing redirect had two places to change. `redeemToken` holds that body. Each route now names only what differs — its path, its audience's reader, its expired reason, the fields it selects, and the single-use check that is genuinely its own. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hc3zguz3NG2Z23EkcWhuWt
Two comments disagreed about `_verified`, and the one claiming every auth collection carries it was false. Payload's `getAuthFields` pushes `verificationFields` only when `auth.verify` is configured, so a served collection without one has no such column. The burn named it unconditionally, which would have selected and written a field that does not exist. It is now read off the sanitized config, the same answer `invitesAccounts` gives the send side. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hc3zguz3NG2Z23EkcWhuWt
`emailFrom` destructures `{ project }` and nothing else. The invitation send
built a whole `LoginMailArgs` to satisfy it, whose `signInUrl` held an
invitation URL under a name claiming the other link kind.
It now takes the project. The fabricated args object is gone, and the
signature no longer promises three inputs the function never reads.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hc3zguz3NG2Z23EkcWhuWt
`ConfirmSignIn` defaulted the heading, lead and submit label, so the sign-in wording sat in the component and the invitation wording at its call site. Reviewing the page's words meant reading both files, and a change to one set read as a change to the component. All three are required now, and both sets sit side by side in `page.tsx`. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hc3zguz3NG2Z23EkcWhuWt
|
All four review threads adopted, none rebutted. Pushed b200312.
Lean gate green. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
One thread answered. Nothing to change, so nothing pushed — head stays feee7a8.
🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Both recipients' buttons are page links whose landing is a signed `to` claim, and `redeemToken` falls back to `/admin` — the dashboard — when that claim is absent. A `to` lost at signing raises nothing: the manager is signed in and dropped on the dashboard, with the event they were asked about nowhere in sight. Only the event manager's end was covered, end to end, by `event-verification.int.spec.ts`. A region manager's link is nothing but this claim, and nothing read it back. Both are pinned now, with the route "Update the details" posts to. Watched failing: `to: '/admin/'` in `reminderButtonUrl` reds both landing assertions. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FbbChBC9d6c19fJngyLcm9
|
One thread adopted. Pushed 28f2024.
Lean gate green at this head: lint, both typechecks, 2237 unit tests. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
One thread asked, nothing adopted. No push — head stays 28f2024.
Every other thread is resolved or already answered at this head. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
One thread decided, nothing to change. No push — head stays 28f2024.
Every thread on this PR is now resolved. Nothing is waiting on me. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
#857 squash-landed as c6511bc, so this branch's copy of its commit shares no ancestry with main's and every file it added came back as an add/add. main's `systemEntities.ts` and `payload-system-access.int.spec.ts` are byte-identical to this branch's base, so taking this side loses nothing — it is that same content plus the three commits here. `docs/rules/access.md` conflicted on the one line #858 rewrites ("both call sites" to "every call site"); main's side was the pre-#858 wording. #853's edit to that file elsewhere merged clean and is kept. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01D33Z68cuaxB8VpGSwhgkjY
Summary
POST, never on theGETa mail scanner makes. "Update the details" on the same page signs the manager in, accepting an imported account, and opens the event.Changes
src/plugins/login/invitations.ts— the queue. A role added, or a document newly naming a manager, is recorded on the manager (pendingInvitation,invitationDueAt).sendInvitationssends what is due every five minutes, ten minutes after the last assignment.src/plugins/login/loginPlugin.ts— a create sends nothing. The queue hooks go on every collection amanagersjoin points at, plusroles. Registers the task and itsinvitationsqueue, and is switched off under seed scripts.src/plugins/login/grantSummary.ts+invite.ts+src/emails/InviteEmail.tsx— what an invitation names, its brand (brandProject), andcomposeInvitation, the one composition every sender runs.src/plugins/login/token.ts,pageLink.ts,endpoints/redeemLink.ts, and the sign-in page's?link=— a third link audience,manager-link: sign in, then land on one admin page. An optionalverifiesclaim names the event a reminder may verify.src/app/(frontend)/events/verify/— rebuilt on that link: the event's details, "Verify this event" (a Server Action), and "Update the details" (aPOSTtoredeem-link).ExpireEvents/verifyUrl.ts'sreminderButtonUrlbuilds each recipient's button. Removed: the oldevent-verifytoken andverifyEventFromToken.new_responsibilitypreference, which nothing sent, becomesinvitation.Preview
?invite=,?token=and now?link=.SMTP_URLis set on this preview, so its mail reaches Mailpit.Email previews
From
scripts/preview-manager-emails.tsandpreview-event-emails.tsat this head. Mailpit keeps them until 2026-10-05.Mailpit's HTML check scores the invitation 91% supported, 7.5% partial, 1.1% unsupported. What remains is layout-wide and cosmetic in Outlook — see Notes.
Migration
src/migrations/20260928_051738_add_manager_invitation_queue.tsmanagersgainspending_invitation(jsonb) andinvitation_due_at(timestamptz, indexed). Both job task-slug enums gainsendInvitations. Each manager'snotification_preferences.new_responsibilityis renamedinvitation, keeping its value.downrenames the key back and drops both columns.Test results
.claude/skills/pr-prep/check.shat this head — lint, typecheck (src), typecheck (tests), 2237 unit testsevent-verification.int.spec.ts36 passed at this head;manager-invite.int.spec.ts24 passedmainmerge (feat(email): send preview mail over Mailpit's HTTP API, so a routine can post links #854, scripts only);event-verification+manager-invite57 passed after the verify page returnedGETs of a verify link left the event unverified; the button verified it (email-linklogged); "Update the details" landed signed in on the event's admin pageManual verification
Notes for reviewer
/events/verify?token=…) now shows "This link has expired" with a sign-in button, until the next reminder arrives.max-width, so every email's card stretches across the window there. The fix is an MSO conditional table inEmailLayout— layout-wide, and worth its own PR where it can be checked in Outlook./admin/. Both recipients' buttons land on the event's own admin page —reminder-button-url.spec.tspins that claim, because a link that lost it would sign the manager in on the dashboard instead.Detail
Why the invitation follows the assignment. An Atlas manager's work is regions and events, and those are joins: nothing can point at an account created a moment before. An invitation sent on create could only ever name roles.
Why queue writes bypass
update. They are bookkeeping on someone else's save.updateruns the manager's hooks and validates the whole stored document, so an imported manager with legacy data failing a newer validator would roll back the region save that named them.payload.db.updateOnewrites the two columns in the caller's transaction, as the meditation weights cache does.Why claim before send. Clearing after the send would wipe an assignment saved while the email rendered. Claiming first means a failed send is not retried. Payload's adapters log rather than throw, so that failure is a render bug, and retrying it every five minutes would mail nothing.
Why the brand follows the listing.
currentProjectis written only byset-project, and an account that has never accepted has never signed in to call it. On its own, it sent every Atlas manager a We Meditate invitation.Seed runs. The importer writes managers onto hundreds of regions and events. With the queue on, production's next run would mail every one of them, so
payload.config.tspassesinvitations: !isSeedScript. The fields and the task are wired either way, so the schema never differs. The importer's andseedPreviewAdmin'sdisableVerificationEmailopt-outs are gone — a create sends nothing now, for everyone.Mutations watched failing. Keeping any current project: three branding specs go red. Dropping the self-change guard: the self-assignment integration spec goes red. Signing
to: '/admin/'instead of the event's path: both reminder-landing assertions go red.Closes #839
🤖 Generated with Claude Code