Skip to content

feat(auth): admin-triggered resend of a manager's verification email - #691

Closed
sydevs-bot wants to merge 5 commits into
mainfrom
claude/feat-resend-manager-verification
Closed

sydevs-bot wants to merge 5 commits into
mainfrom
claude/feat-resend-manager-verification

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #680.

A manager whose verification email never arrived can now be rescued with a button instead of a database edit. Payload ships no resend operation — its auth surface is forgotPassword / login / logout / me / refresh / resetPassword / unlock / verifyEmail, and payload.verifyEmail() consumes a token rather than issuing one — so the only fix was an admin ticking _verified by hand, which skips verification rather than performing it. The upstream request (payloadcms/payload#7701) has sat unassigned since 2024.

An unverified manager's edit view gains Resend verification email; a verified one gets nothing at all, rather than a disabled control.

⚠ One open question for the reviewer: should the token rotate?

This is the only thing outstanding, and it is a decision rather than a defect — see the thread. Rotating the token is what generates the drop-detection machinery: the { ok: false } returns in resendAdapter, the restore branch, the 502, the docs/rules/email.md section, and two of the nine watched-failing defects. Re-sending the existing token unchanged would remove that failure mode rather than defend against it, since the same secret goes to the same address either way and this endpoint cannot change the address.

AC 3 of #680 asks for rotation, but that acceptance criterion is loop-authored — the approval on the ticket was "Let's implement this". Either answer is defensible; the loop should not pick it on its own authority. Everything else on the PR is settled.

Shape (a) from the ticket, and that choice is the security model

Admin-only, not a public "resend" on the login screen. No public surface means no account-enumeration oracle and no email-bomb amplifier pointed at an address the caller names — so there is no Turnstile and no rate limiter here to get subtly wrong. A public variant needs all three and is a different ticket.

Two things worth reading the diff for

The email is rendered by the collection's own auth.verify.generateEmailHTML, read off the sanitized config rather than reimplemented. Payload's internal sendVerificationEmail does this job but is not exported from the package root, and reaching into dist/ would couple us to its build layout. Rendering from the config is what makes drift impossible — and that drift is exactly what #320 was: a verify link missing its collection slug, which fails silently, because isPublicAdminRoute waves any /verify/ path past the auth gate.

A dropped send no longer revokes a working link. payload.sendEmail does not throw here — every failure path in resendAdapter returns instead, deliberately, since the same adapter runs inside the manager-create transaction where a throw would roll the account back. So a try/catch alone would have reported success for a message that was dropped, after rotating the token. The adapter's three drop paths return { ok: false, reason } beside the Sentry capture they already made, and the endpoint puts the previous token back and answers 502.

Only an explicit ok: false counts as a drop: Payload's console adapter stands in wherever email is unconfigured and resolves undefined, which must keep reading as sent. That union is exported as EmailSendResult rather than retyped at the call site.

Review round — six threads, five closed

What the adversarial review found and what changed in a141c75
Thread Outcome
Restore write inside the outer try Fixed. A restore that itself threw fell into the generic 500 — describing a no-op for the one outcome where the manager is worse off than before the call. It has its own catch and a 502 that says the link was revoked
showHiddenFields comment named the wrong field Fixed. _verified is an ordinary checkbox; hidden: true is on _verificationToken alone (payload/dist/auth/baseFields/verification.js). The admin edit view depends on that, since it fetches without the flag
Hand-written credential projection Replaced with select. hash / salt / resetPasswordToken never enter the document, so the guarantee is structural rather than a warning comment
Linear scan over config.collections Fixed. req.payload.collections.managers?.config.auth?.verify — the cast and the SanitizedCollectionConfig import went with it
Three restatements of generated types Fixed. Manager already declares both fields and payload.update's data is already DeepPartial<Manager>. Both typecheck lanes pass without the casts
ui field had no admin.condition Fixed. managers is not in RESTRICTED_COLLECTIONS, so a non-admin manager could read a colleague's document and was offered a button that could only 403. adminOnlyCondition is the same predicate the endpoint calls
Should the token rotate at all? Open — yours. See above

Field placement (sidebar vs mid-form) was raised and deliberately not changed: a UX judgement about a screen nobody has looked at, and the one suggestion here with no way to check itself.

Review aids

Preview: Railway builds the per-PR environment on push. The surface is POST /api/managers/:id/resend-verification plus the button on /admin/collections/managers/:id for an unverified manager — a fresh preview may have none, in which case create one to see the control.

Test results

Every assertion was watched FAILING — nine defects, each at the site that would really cause it
Defect reintroduced What goes red
Re-send the existing token instead of minting one the rotation case — the old link still verifies
Hand-write the email instead of using the collection's template the template case — bodies no longer match once tokens are blanked
Drop the already-verified guard the 409 case
Drop the admin gate the refusal case, for all four caller shapes
Move the admin gate to after the token write the refusal case — proves the ordering assertion is not decorative
Drop the id validation the 400 case
Ignore a dropped send (the pre-review behaviour) the restore case — token left rotated
Report the drop but skip the restore the restore case — so both halves are load-bearing
Put the restore back inside the outer try (this round) the new restore-failure case — expected 500 to be 502

One assertion was vacuous first, and this is the useful part. The non-admin case passed undefined as the caller, which fell through to the test helper's default parameter and ran the case as the admin — a 200 read as a pass. It is null now, with a comment saying why. read() ?? fallback in a spec is the local shape of this.

The new case guards against the same trap from the other side: it asserts the restore was attempted (updates === 2), so it cannot pass by the rotation write throwing instead.

Security review — what it found, and the reachability check it could not make

A security review ran (the change touches src/collections/Managers/ and src/collections/*/endpoints/, both securityReview.triggerPattern paths). It found the gate sound — no unauthenticated caller, ordinary manager, inactive manager or API client can reach any effect; the 403 is returned before routeParams is read, so there is no enumeration oracle; the token is 160 CSPRNG bits matching Payload's own create path; nothing carries a token into a log, a response or a Sentry capture. Both of its findings were fixed in 8582348: the dropped-send defect above, and showHiddenFields: true handing hash / salt / resetPasswordToken to the template renderer. That second one is now closed at the framework rather than by hand — see the select row above.

It flagged one thing as unverifiable from source: the specs call resendVerification.handler() with a hand-built request, so routing and real auth population are exercised by nothing. Checked against a booted dev server:

Request Result
POST /api/managers/1/resend-verification, no credentials 403 — path registered, gate fires
POST /api/managers/not-a-number/… 403 — gate runs before id parsing
POST /api/managers/1/no-such-endpoint (control) 404 — so the 403s are this handler, not a catch-all
Fixture pre-mortem

The specs assume the test Payload carries the real Managers.auth.verify.generateEmailHTML — "the resend renders the same email the create path does" is the property under test, and a stubbed template would make it vacuous. Verified in tests/utils/testHelpers.ts:53-65: getTestCollections() maps over the real collections export and only rewrites upload on UPLOAD_COLLECTIONS, which managers is not, so the collection reaches the test config untouched.

Manual verification

  1. Create a manager in the preview admin; confirm the button appears while unverified and disappears after verifying — and that a non-admin manager never sees it.
  2. Click it, open the second email in Mailpit, and confirm the link logs in — and that the first email's link no longer does.

🤖 Written by the sydevs autonomous loop — see what this is


🤖 Generated with Claude Code

https://claude.ai/code/session_01KhLvw4PKkZTMqSppPDU3k8

Closes #680.

A manager whose verification email bounced, spam-foldered or was dropped by
Resend had exactly one rescue: an admin setting `_verified` by hand in the
database, which skips verification rather than performing it. Payload ships
no resend operation — its auth surface is forgotPassword / login / logout /
me / refresh / resetPassword / unlock / verifyEmail, and `payload.verifyEmail`
CONSUMES a token rather than issuing one — and the upstream request has sat
unassigned since 2024 (payloadcms/payload#7701), so waiting was not a plan.

Shape (a) from the ticket: an admin-only row action, not a public "resend"
on the login screen. That choice is the entire security model — no public
surface means no account-enumeration oracle and no email-bomb amplifier
pointed at an address the caller names, so no Turnstile and no rate limiter
to get right. A public variant needs all three and is a different ticket.

The email is rendered by the collection's own `auth.verify.generateEmailHTML`,
read off the sanitized config rather than re-implemented. Payload's internal
`sendVerificationEmail` does this job but is not exported from the package
root, and reaching into `dist/` would couple us to its build layout. Rendering
from the config is what makes drift impossible — and that drift is exactly
what #320 was: a verify link missing its collection slug, which fails
SILENTLY because `isPublicAdminRoute` waves any `/verify/` path past the auth
gate.

The token write is what revokes the old link: the column holds one value, so
the previous email stops verifying the moment the new one lands. The admin
gate runs BEFORE that write, so a refused caller cannot invalidate the
outstanding link of the manager it declined to help.

No migration: a `ui` field is not persisted and `_verificationToken` is an
existing auth column. `pnpm generate:types` produces no diff, and the
integration lane's full-schema push succeeds against the changed config.

Tests: six cases in tests/int/manager-verification.int.spec.ts, extending the
#320 loop rather than starting a new file. Every one was watched FAILING with
the defect reintroduced at the site that would really cause it — token reuse
instead of rotation, a hand-written email in place of the template, the
already-verified guard dropped, the admin gate dropped, the admin gate moved
to AFTER the token write, and the id validation dropped. The non-admin case
was itself vacuous first: `undefined` as the caller fell through to the test
helper's default parameter and ran as the admin, so it passed for the wrong
reason until it was changed to `null`.

Fixture pre-mortem: the specs assume the test Payload carries the REAL
Managers `auth.verify.generateEmailHTML`, since "the resend renders the same
email the create path does" is the property under test and a stub would make
it vacuous. Verified in tests/utils/testHelpers.ts:53-65 — `getTestCollections`
maps over the real `collections` export and only rewrites `upload` on
UPLOAD_COLLECTIONS, which `managers` is not.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014oQ3V1YBH5pnFvprMCbB6A
Both findings from the security review of this PR's endpoint.

**A dropped email reported success, after destroying the old token.**
`payload.sendEmail` does not throw here: every failure path in
`resendAdapter` returns instead, deliberately, because the same adapter runs
inside the manager-create transaction where a throw would roll the account
back. So the endpoint's try/catch was dead code for the ordinary delivery
failure — a missing RESEND_API_KEY, a Resend outage — and the sequence was:
rotate the token (revoking the link the manager may already be holding),
drop the message, log "re-sent", return 200. That is the #320/#675 silent
email failure, reintroduced on the path built to rescue it.

The adapter's three drop paths now return `{ ok: false, reason }` alongside
the Sentry capture they already made. It is a return value, not a throw, so
the non-fatal contract is unchanged and every existing caller — all of which
ignore the result — behaves exactly as before. Only an explicit `ok: false`
counts: Payload's console adapter stands in wherever email is unconfigured
and resolves undefined, which must keep reading as sent.

The endpoint restores the previous token when it sees a drop, rather than
merely reporting one. A failed resend now leaves the manager exactly as it
found them, with any outstanding link still working, and answers 502 saying
so — which is strictly better than telling an admin to retry an account they
have just locked out of its own rescue.

**The password hash was being handed to the email template renderer.**
`showHiddenFields: true` returns `hash`, `salt` and `resetPasswordToken` too,
and the whole object was spread into the `user` passed to
`generateEmailHTML`, whose output is emailed. Nothing reads them —
`VerifyEmail` takes `name` and `email` — so this was never exploitable, but
it is live credentials crossing into a renderer one careless template edit
from mattering, and it is wider than Payload's own create path, which passes
the post-afterRead doc with hidden fields stripped. Now an explicit
projection of id / name / email / collection / the new token.

The new assertion was watched failing twice, at both sites that would really
cause it: ignoring the drop (the behaviour above) leaves the token rotated,
and reporting the drop without restoring leaves it rotated too. Both go red;
neither half of the assertion is decorative.

Also verified since the review, which flagged it as unchecked: the route is
genuinely reachable and the gate genuinely fires on a real HTTP request.
Against a booted dev server, `POST /api/managers/1/resend-verification` with
no credentials answers 403 while `POST /api/managers/1/no-such-endpoint`
answers 404 — so the path is registered, `routeParams.id` arrives, and the
403 is this handler rather than a catch-all. The integration specs call the
handler directly and cannot see any of that.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014oQ3V1YBH5pnFvprMCbB6A
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-691 September 3, 2026 23:38 Destroyed
@railway-app

railway-app Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-691 environment in sahajcloud

Service Status Web Updated
SahajCloud ✅ Success (View Logs) Sep 4, 2026 at 1:17 pm UTC
1 service not affected by this PR
  • mailpit

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🧐 Adversarial review

This is the ticket's shape (a), built where the ticket said to build it, and the load-bearing choice — rendering the email from the collection's own auth.verify rather than a second copy — is right, and is what makes the #320 drift class structurally impossible here rather than merely absent. The admin-only gate genuinely is the security model: with no public surface there is no enumeration oracle and no amplifier, and the endpoint reaches for the same isAdminManager predicate the rest of the codebase uses. The specs are unusually strong — eight defects watched failing, one of them proving the gate runs before the token write, which is the assertion most people skip.

My one shape-level doubt is that a single decision generates roughly a third of the diff, and I cannot find what it buys. Rotating the token instead of re-sending the existing one is what creates the drop-detection problem — and the { ok: false } returns in resendAdapter, the new docs/rules/email.md section, the restore branch, the 502 and two of the eight defects all exist to solve it. The same secret goes to the same address, and this endpoint cannot change the address, so rotation's only reliable effect is to kill a link the recipient may still be holding. AC 3 asks for it, but that AC is loop-authored; the human approval was "Let's implement this". Worth settling deliberately rather than inheriting.

Everything else is small and local: three casts that restate what payload-types.ts already declares, one .find() over config.collections where Payload has a typed accessor, a comment that has the wrong field hidden, and a ui field with no admin.condition.

Findings

  • should-fix — Token rotation is the source of most of this diff's complexity, and re-sending the existing token removes the failure mode instead of defending against it — plus a gap in the restore guarantee if rotation stays (thread, resendVerification.ts:112).
  • should-fix — req.payload.collections.managers?.config.auth?.verify replaces the linear scan, the cast and the extra type import (resendVerification.ts:96-100).
  • should-fix — Manager already declares _verified and _verificationToken, and GeneratedTypes is augmented, so & { _verified } and both as Partial<Manager> casts restate the generated type (resendVerification.ts:81, :124, :170).
  • consider — The showHiddenFields comment names the wrong field, and the client component depends on the opposite being true; a select would also retire the hand-written projection (resendVerification.ts:70-78).
  • consider — Export the adapter's result type instead of retyping its shape at the call site (resendVerification.ts:159-161).
  • consider — The ui field has no admin.condition, so non-admin managers are offered a button that can only 403; adminOnlyCondition exists for this (Managers.ts:79-89).

No blockers. Nothing here touches a cross-repo contract: managers is admin-only, in no project, absent from CUSTOM_ENDPOINT_PATHS (checked — set-project is too, so the precedent holds), and pnpm generate:types produces no diff, so no consumer repo's types:cms sync is affected.

What was checked

  • Ticket and its thread — #680 including all three comments, to separate what the human approved ("Let's implement this", 2026-09-03) from what the loop's own ticket and follow-up comment assumed. That separation is the basis of the rotation finding.
  • The diff — all 8 files, origin/main...origin/claude/feat-resend-manager-verification (526+/7−), read whole rather than as a diff.
  • Payload's installed source, since three of this PR's claims are assertions about it:
    • payload/dist/auth/baseFields/verification.js — _verified is a checkbox with defaultAccess read; hidden: true is on _verificationToken only. This contradicts the endpoint's comment at :70-72 and is what the fourth finding rests on.
    • payload/dist/auth/baseFields/auth.js — confirms hash / salt / resetPasswordToken are the hidden fields the projection warning is about.
    • payload/dist/index.js:415-416 and dist/email/types.d.ts — payload.sendEmail returns the adapter's value unwrapped, so the drop mechanism does work; EmailAdapter<T> is generic but Payload['sendEmail'] is not, so the call-site cast is unavoidable.
    • payload/dist/email/consoleEmailAdapter.js — resolves undefined, so result?.ok === false (not !result?.ok) is correct, as both comments claim.
    • payload/dist/collections/config/types.d.ts:690 and dist/index.d.ts:251 — payload.collections[slug].config is the typed lookup the endpoint hand-rolls.
    • payload/dist/collections/operations/local/update.d.ts:25 — data is DeepPartial<RequiredDataFromCollectionSlug<TSlug>>, so no cast is needed.
  • The consumer side of the component's assumption — @payloadcms/next/dist/views/Document/getDocumentData.js:23-33 fetches without showHiddenFields, which is why the _verified question is a real one and not pedantry. @payloadcms/ui's DocumentInfo types confirm initialData exists and is optional.
  • This repo's own rules and precedents — docs/rules/endpoints.md (admin-only endpoints may skip requireActiveClient if they say why: this one does; OpenAPI registration is required for client-facing endpoints only), docs/rules/access.md plus permissions.ts:88 and config/projects.ts:171-175 (which is how I established that a non-admin manager can read another manager), adminOnly.ts (isAdminManager is type === 'admin', so an inactive admin is not a thing and the guard is sound), setProject.ts as the sibling endpoint, and payload-types.ts:1358-1359 / :7157.
  • Not run: no tests, no typecheck — this checkout is detached at origin/main with the PR branch fetched read-only. The three type findings are argued from the declarations above rather than from a compiler run, so treat them as questions if tsc disagrees.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

return denied('Verification email is not configured.', 500)
}

const token = generateVerificationToken()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is rotating the token actually wanted here? It is the one decision that generates most of this PR. The { ok: false, reason } returns in resendAdapter, the new docs/rules/email.md section, the restore branch at 163–183, the 502, and two of the eight watched-failing defects all exist to stop a dropped send from leaving a manager with a revoked link and nothing in its place.

Re-sending manager._verificationToken unchanged — minting only when it is null — removes that failure mode instead of defending against it: a dropped send would change nothing, so there would be nothing to restore, and the endpoint would be a read plus a send. As far as I can tell rotation buys nothing in exchange: the same secret goes to the same address it was already sent to, and this endpoint cannot change the address, so the only thing rotation reliably does is invalidate a link the recipient may still be holding (spam-foldered, not lost). AC 3 in #680 does ask for rotation, but that AC is loop-authored — the approval on the ticket was "Let's implement this", not a ruling on token lifetime.

Push back if rotation is deliberate — a stale link living forever is a defensible thing to dislike. But it should be a decision someone made, not a line item that quietly costs a third of the diff.

Secondary point, only if rotation stays: the restore payload.update at 167 sits inside the same try, so if it throws, control lands in the catch at 184 and returns the generic 500 — token rotated, not restored, and that copy says nothing about the link that just died. "A failed resend leaves the manager exactly as it found them" holds for a dropped send but not for a failed restore.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Splitting this thread: the secondary point is fixed in a141c75; the rotation question is left open for @Ardnived, because it is a decision rather than a defect.

Fixed — the failed-restore hole. You are right that payload.update at 167 sat inside the outer try, so a restore that itself threw landed in the catch and answered the generic 500 ("Could not send the verification email. Please try again.") — describing a no-op, for the one outcome where the manager is genuinely worse off than before the call. It has its own catch now and returns a 502 that says the earlier link has been revoked and another must be sent. This holds whichever way the rotation question goes, which is why it did not wait on it.

Watched failing at the site that causes it, per the repo's rule: with the inner catch removed the new case reports expected 500 to be 502. tests/int/manager-verification.int.spec.ts — "says the link was revoked when the RESTORE itself fails". It also asserts the restore was attempted (updates === 2), so the case cannot pass by the rotation write throwing instead.

Open — should the token rotate at all? I have not changed this, and I do not think a run should decide it. The argument stands as written: the same secret goes to the same address, this endpoint cannot change the address, so rotation's one reliable effect is to kill a link the recipient may still be holding — and it is what generates the { ok: false } return, the restore branch, the 502, the docs/rules/email.md section and two of the eight watched-failing defects. Re-sending manager._verificationToken unchanged (minting only when null) would delete that whole failure mode rather than defending against it.

What stops me acting on my own argument is that AC 3 of #680 asks for rotation, and I wrote AC 3. Your approval on the ticket was "Let's implement this", not a ruling on token lifetime, so the loop treating its own acceptance criterion as authorisation to keep it — or to drop it — is the loop grading its own homework either way.

So:

the two things that would change if you say "don't rotate"

  • resendVerification.ts loses the rotation write, previousToken, the restore branch (both catches), and the 502 — roughly a third of the file.
  • resendAdapter.ts's { ok: false, reason } returns and EmailSendResult would have no consumer left. I would keep them: the adapter reporting a drop is right independent of who reads it, and docs/rules/email.md documents it as the contract. But the endpoint would stop being the reason they exist.

Not affected either way: the admin gate, the template-from-config rendering, the 409/404/400/422 paths, and six of the eight defect cases.

A stale link living forever is a defensible thing to dislike, so "keep rotation" is a fine answer — I only want it to be an answer.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread src/collections/Managers/Managers.ts Resolved
Five of the six threads on #691, all raised by the loop's own adversarial
review. The sixth — whether rotating the token is wanted at all — is a
decision rather than a defect and is left open for the reviewer.

**A failed restore no longer reports that nothing happened.** The restore
write sat inside the outer `try`, so a restore that itself threw landed in
the generic 500 ("Could not send … please try again") — for the single
outcome where the manager is genuinely worse off than before the call,
holding a link that has been revoked and not replaced. It now has its own
catch and a 502 whose copy says the link was revoked. Watched failing at
that exact site: with the inner catch removed the new case reports
`expected 500 to be 502`.

**The read is projected by the framework, and its comment was wrong.**
`_verified` is not a hidden field — `payload/dist/auth/baseFields/
verification.js` puts `hidden: true` on `_verificationToken` alone and
leaves `_verified` an ordinary checkbox with `defaultAccess` read. The old
comment claimed the opposite, and `ResendVerification.tsx` depends on the
truth: it reads `_verified` off a document the admin view fetches *without*
`showHiddenFields`. A `select` now keeps `hash`, `salt` and
`resetPasswordToken` out of the document entirely, which is the guarantee
the twelve-line warning above the hand-written projection was standing in
for.

**Three restatements of generated types removed.** `Manager` already
declares `_verified` and `_verificationToken` (`payload-types.ts:1358-1359`)
and the `GeneratedTypes` augmentation makes `payload.update`'s `data`
already `DeepPartial<Manager>`, so the intersection and both
`as Partial<Manager>` casts said nothing the compiler did not know. Same in
the spec's `tokenOf`.

**`req.payload.collections.managers?.config.auth?.verify`** replaces the
linear scan over `config.collections` plus its cast and type import —
`Collection['config']` is `SanitizedCollectionConfig` already.

**`EmailSendResult` is exported** from the adapter instead of retyped
structurally at the call site, so a fourth drop path reaches this reader
through the compiler. The cast stays: the `EmailAdapter` generic does not
reach `payload.sendEmail`.

**The `ui` field gains `adminOnlyCondition`.** `managers` is not in
`RESTRICTED_COLLECTIONS`, so a non-admin manager can read a colleague's
document and was being offered a button that could only ever 403.

Gate: lint, typecheck, typecheck:tests, test:unit (120 files / 1564 specs)
and the targeted `manager-verification` int spec (8 cases) all green.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KhLvw4PKkZTMqSppPDU3k8
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-691 September 4, 2026 13:15 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Five of the six review threads are closed in a141c75; the sixth is a decision for you and is the only thing this PR is now waiting on.

The open one: should the verification token rotate at all? (thread). Rotation is what generates the drop-detection machinery — the adapter's { ok: false } returns, the restore branch, the 502, the docs/rules/email.md section — and re-sending the existing token would remove that failure mode rather than defend against it. AC 3 of #680 asks for rotation, but I wrote AC 3; your approval was "Let's implement this", not a ruling on token lifetime. Either answer is fine, and the thread lists what changes under each.

One real defect came out of the round. The restore write sat inside the outer try, so a restore that itself threw answered the generic 500 — "please try again" — for the single outcome where the manager is genuinely worse off than before the call: holding a link that has been revoked and not replaced. It has its own catch now and a 502 whose copy says so. Watched failing at that exact site (expected 500 to be 502).

The other four were the corrections you'd expect: a comment that named the wrong field (_verified is not hidden — _verificationToken is, and the admin edit view depends on that), the hand-written credential projection replaced by a select so hash/salt never enter the document at all, a linear scan replaced by Payload's own slug index, and three casts that restated payload-types.ts.

Gate, and one thing deliberately not done

Lint, typecheck, typecheck:tests, test:unit (120 files / 1564 specs) and the targeted manager-verification integration spec (8 cases) are all green on a141c75. Both typecheck lanes passing with the casts removed is the evidence that the compiler already knew what they restated.

Not done: moving the button to the sidebar. It was raised in the same thread as the admin.condition fix, but it is a UX judgement about a screen nobody has looked at and the one suggestion here with no way to check itself. One line if you want it.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@Ardnived

Ardnived commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Closed for now, we want to explore an alternative where users are sent invitations instead of verifications

@Ardnived Ardnived closed this Sep 5, 2026
@github-project-automation github-project-automation Bot moved this from In progress to Done in SYDevelopers Technical Roadmap Sep 5, 2026
@Ardnived Ardnived removed the awaiting label Sep 5, 2026
Ardnived added a commit that referenced this pull request Sep 5, 2026
)

Rewrites every in-scope prose file (67 of 69 flagged by the audit) into
strict Simplified Technical English and retires D1/Cloudflare Workers-era
debris three months after the Postgres/Railway migration. Tracked *.md
(excluding CLAUDE.md symlinks and the vendored .agents/skills/payload/
skill, left untouched pending ownership confirmation) drops from 770,090
to 600,797 chars (22%). The five hot-path files auto-imported every
session (AGENTS.md, docs/architecture.md, docs/environment.md,
docs/code-style.md, .claude/workflow.json) drop from 84,492 to 36,397
chars (57%).

Deleted (dead, zero referrers, grepped clean): seed-issues-report.md,
src/migrations/README.md (its one fact folded into src/migrations/AGENTS.md).

Merged: DEPLOYMENT.md + RAILWAY_RUNBOOK.md split by lifecycle (how it runs
today vs. provision-from-scratch/disaster-recovery), resolving their
D1-decommission contradiction — PR #468 (merged 2026-06-08) confirms the
Worker is gone, so the stale "Remaining (gated)" TODOs are removed, not
reworded.

Legacy debris fixed (D1/SQLite/Cloudflare-Workers-as-current retired):
migration-reviewer.md's whole persona rewritten for Postgres/Drizzle,
seeds/wemeditate/AGENTS.md's Dual-Database table corrected to Postgres,
src/globals/AGENTS.md's json_array() rationale corrected to Postgres's
real FUNC_MAX_ARGS=100 limit, docs/mcp-setup.md's cloudflare-docs row
drops Workers/D1. grep for D1|SQLite|Cloudflare Workers across
.claude/agents/, seeds/wemeditate/, src/globals/, docs/mcp-setup.md is
clean. README.md's stale `cd sy-devs-cms` corrected to `cd SahajCloud`.

Mandatory AGENTS.md fixes applied: dropped the nonexistent `pnpm
test:e2e`, replaced the broken dev-server.sh path with the
`/workflow:dev-server` skill, fixed the seeds/atlas/MIGRATION_PLAN.md:103
anchor (now resolves to `AGENTS.md#website-selection-rules-584`),
collapsed duplicate PR-workflow/test-tier prose into single pointers to
testing-reqs.md and the finalize-pr skill.

Traps preserved (compressed, never deleted): the conflicted-PR "zero CI"
diagnostic with its docs/why.md anchor and #632/#653 numbers; the Cache
Rule authorization-header predicate and root-endpoint fix; DB_QUERY_LOGGING
and TURNSTILE_SECRET_KEY footguns; storage.md's preview/prod asset-isolation
risk; the payload-cli silent-exit/hang ladder; the migration snapshot
out-of-order duplicate-re-emission trap; access.md's per-locale-roles
gotcha (#665); endpoints.md's root-endpoint hook gap; email.md's two-
token-URL-shapes bug; seeds/atlas/AGENTS.md's silent-rollback-on-trashed-
relation trap; the never-name-a-global-field-locales rule. The 2026-08-27
dated Admin Access exception is kept (still current).

Comment sweep: rewrote comments to STE in every file the audit flagged
as touched (route.ts's mandatory dead-comment deletions, r2NativeAdapter.ts,
Icon.tsx, scalarPlugin.ts, env/server.ts, localizedRolesAuth.ts, plus the
full tests/seeds/scripts/.claude/root-config/.github sweep — 227 files
total). Verified comment-only: every changed line in every .ts/.tsx/.mjs/
.cjs/.sh/.py file has an identical code portion before its comment marker;
zero functional changes. Deleted a dead `sharp` import and several doc-
duplicating/obvious comments (e.g. vitest.setup.ts's two narrate-the-
obvious lines).

Verification run as finisher: pnpm lint, typecheck, typecheck:tests, and
the full unit lane (1564 tests) all pass, plus targeted integration specs
for every touched collection/access path (events, regions, role-based-
access — 79 tests, live Postgres). ste-lint.py run on all 40 changed .md
files: hard violations cut from 169 to 118, concentrated in five already-
dense reference docs (admin-ui/api-clients/email/endpoints/openapi/
storage.md) where the prior compression pass already prioritized fidelity
over the linter's raw sentence-length cap; remaining flags are verified
domain terms (Railway's "Health Check", Zod's "Validate", literal HTTP
methods GET/DELETE, SQL "cascade delete", TS "type erasure") or residue
in those five files. rule-delta.mjs vs main on AGENTS.md/docs/rules/*.md/
migration-reviewer.md: 3 directives flagged REMOVED, all three verified
as de-bolded (not deleted) — "GET /api/events/geojson always excluded,
no opt-out" (api-clients.md) and the two CPU parallel-test-run rules
(testing-reqs.md) all still present as plain bullets/cells, content
identical. 1 flagged ADDED is the same pass-by-reference comment rule
gaining full-sentence bold (previously invisible to the tool since only
"Do not" was bold). Sequencing: PRs #692 (UNKNOWN), #686 (BLOCKED, not
CONFLICTING), #691 (CLEAN) show no current CONFLICTING/DIRTY state, so
this PR is not blocked today, though #692/#691 touch overlapping files
and should land or be watched. securityReview trigger paths (access/,
storage/, api routes, webhook scripts) all confirmed comment-only.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Ardnived pushed a commit that referenced this pull request Nov 5, 2026
Five of the six threads on #691, all raised by the loop's own adversarial
review. The sixth — whether rotating the token is wanted at all — is a
decision rather than a defect and is left open for the reviewer.

**A failed restore no longer reports that nothing happened.** The restore
write sat inside the outer `try`, so a restore that itself threw landed in
the generic 500 ("Could not send … please try again") — for the single
outcome where the manager is genuinely worse off than before the call,
holding a link that has been revoked and not replaced. It now has its own
catch and a 502 whose copy says the link was revoked. Watched failing at
that exact site: with the inner catch removed the new case reports
`expected 500 to be 502`.

**The read is projected by the framework, and its comment was wrong.**
`_verified` is not a hidden field — `payload/dist/auth/baseFields/
verification.js` puts `hidden: true` on `_verificationToken` alone and
leaves `_verified` an ordinary checkbox with `defaultAccess` read. The old
comment claimed the opposite, and `ResendVerification.tsx` depends on the
truth: it reads `_verified` off a document the admin view fetches *without*
`showHiddenFields`. A `select` now keeps `hash`, `salt` and
`resetPasswordToken` out of the document entirely, which is the guarantee
the twelve-line warning above the hand-written projection was standing in
for.

**Three restatements of generated types removed.** `Manager` already
declares `_verified` and `_verificationToken` (`payload-types.ts:1358-1359`)
and the `GeneratedTypes` augmentation makes `payload.update`'s `data`
already `DeepPartial<Manager>`, so the intersection and both
`as Partial<Manager>` casts said nothing the compiler did not know. Same in
the spec's `tokenOf`.

**`req.payload.collections.managers?.config.auth?.verify`** replaces the
linear scan over `config.collections` plus its cast and type import —
`Collection['config']` is `SanitizedCollectionConfig` already.

**`EmailSendResult` is exported** from the adapter instead of retyped
structurally at the call site, so a fourth drop path reaches this reader
through the compiler. The cast stays: the `EmailAdapter` generic does not
reach `payload.sendEmail`.

**The `ui` field gains `adminOnlyCondition`.** `managers` is not in
`RESTRICTED_COLLECTIONS`, so a non-admin manager can read a colleague's
document and was being offered a button that could only ever 403.

Gate: lint, typecheck, typecheck:tests, test:unit (120 files / 1564 specs)
and the targeted `manager-verification` int spec (8 cases) all green.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KhLvw4PKkZTMqSppPDU3k8

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-691 — a141c75e Deployed Sep 4, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

feat(auth): a manager whose verification email never arrived needs a database edit to rescue

3 participants