Skip to content

feat(auth): the login plugin, with magic-link request and redeem endpoints - #847

Merged
sydevs-bot merged 23 commits into
mainfrom
claude/feat-837-magic-link-login
Sep 24, 2026
Merged

sydevs-bot merged 23 commits into
mainfrom
claude/feat-837-magic-link-login

Conversation

@sydevs-bot

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

Copy link
Copy Markdown
Contributor

Summary

  • A manager can now trade an emailed link for an admin session. Passwords keep working — this adds a second way in, and the cut-over that removes the first comes later.
  • createSession generalises past managers, per @Ardnived's decision on #846, and refuses a collection that cannot hold a session.
  • One new nullable column, managers.magic_link_issued_at. No behaviour changes for anyone who does not request a link.

Changes

  • src/plugins/login/ — loginPlugin (the field plus all three endpoints, per collection its collections option names), endpoints/{requestMagicLink,confirmMagicLink,redeemMagicLink}.ts (the handlers, as factories), page.ts (the confirmation page, and the refusals a browser gets), mail.ts (the sign-in message every served collection gets), types.ts (LoginCollectionConfig), token.ts (the two link kinds as separate JWT audiences), and session.ts generalised to createSession(payload, slug, id).
  • src/collections/Managers/login.ts — the two things only managers can answer: the inactive predicate, and which project brands the mail.
  • src/emails/SignInLinkEmail.tsx — the message.

magicLinkIssuedAt carries three jobs at once, which is the design's load-bearing economy: it is the 60-second send throttle, it is the nonce the redeem route matches exactly, and clearing it is what makes a link single-use and what a fresh request does to the outstanding one.

Preview

  • Managers list — the new column is admin.hidden, so nothing should appear here; that is the assertion.
  • Any manager's editor — same, plus the Current Project switcher still works (the endpoint the plugin must not have replaced).
  • Login — password login is untouched.

Migration

  • New migration: src/migrations/20260923_161630_add_manager_magic_link.ts
  • Impact: adds managers.magic_link_issued_at (timestamp(3) with time zone, nullable). No data transformed, no rows touched.
  • Reversible: yes — down drops the column, and nothing else reads it.

Test results

  • Lean gate: ✓ pnpm lint, pnpm typecheck, pnpm typecheck:tests, pnpm test:unit (161 files, 2179 tests)
  • Targeted specs: 22 in tests/int/manager-magic-link.int.spec.ts, plus login-session, role-based-access, managers-access, and the five specs that use createRestClientAs — all passed
  • Full pnpm test:int: ✓ 85 files, 1406 tests
  • Build: N/A — Railway builds; CI does not

Notes for reviewer

Sixth review round: the mail-scanner hazard is closed. The GET that spent the link is now a confirmation page, and the burn moved to POST /api/<slug>/redeem-magic-link (36e48f5). Defender Safe Links and Proofpoint fetch links; they neither POST nor click, so a scan costs the recipient nothing and the owner still signs in with one click.

The page carries no script and no meta refresh, and that is the defence rather than a style choice — anything that submitted the form by itself would hand the link straight back to the scanner. The integration spec asserts their absence for that reason.

Two consequences worth naming. The GET verifies the token, reading no document, so a dead link says so instead of offering a button that fails. And both handlers now answer a browser, so their refusals are HTML pages rather than error envelopes. tests/unit/login-plugin.spec.ts asserts <method> <path> instead of the path alone, since which verb each handler answers is now the security property.

Fifth review round: the route paths. /request-link and /consume-link are now /request-magic-link and /redeem-magic-link (0ace32d), matching requestMagicLink.ts and redeemMagicLink.ts. REQUEST_MAGIC_LINK_PATH and REDEEM_MAGIC_LINK_PATH follow.

⚠ Three earlier rounds defended the old paths on a claim that was wrong. They said #837 published them. It does not: its checklist spells the route <request path>, a placeholder. @Ardnived's "no links have been delivered yet" removed the other reason, and the rename cost one commit.

Of the two threads that asked whether a piece of this should exist at all, both are now settled:

  • Does the request route need to be an endpoint? Leave as is. The link is made server-side and never leaves it: the response is {ok:true} for every outcome, and the token reaches only the stored address. Payload's own POST /forgot-password is anonymous for the same reason.
  • Is inline sendEmail canonical, or should this be a job? Leave as is, per your call. payload.sendEmail is the email adapter's one entry point, and Payload's own verify and reset mail call it inline. Queueing this send stays available, and it is the same decision as the timing oracle below rather than a separate one.

The mail lives in the plugin. src/plugins/login/mail.ts renders SignInLinkEmail and the subject for every served collection, and a collection overrides either half through a generateEmailHTML / generateEmailSubject pair shaped exactly like the one Managers.auth.verify already takes. LoginMail is gone, and the envelope From left the config surface with it: every collection this plugin can serve is an auth collection, so MANAGER_EMAIL_FROM is the sender by construction.

⚠ One divergence worth your eye. The mail is branded for the recipient's currentProject, per review — but #483 decided the opposite for the verify and reset mail, which take the default brand whoever the recipient is. The two auth paths now disagree. It is noted at the call site; say which way you want it and both can follow.

An entry is a config, not a bare slug, and that is the one thing left to check. slug is the only required member now: the plugin renders and addresses the mail itself, so an entry carries only what reads a field the plugin cannot know the name of — isEligible and project — plus the select that makes those two readable. That thread stays open for your veto; a bare list is a smaller change from here than it was.

Token audiences stay manager-signin / manager-invite. Cross-collection replay is already refused by the collection claim, which the redeem route compares against its own configured slug, so renaming them would churn a pinned security constant to no effect.

One open security finding, not fixed. request-magic-link answers identically for every outcome in status, body and headers — but not in elapsed time. An unknown address does one indexed read; a real one also writes, signs, renders and sends inline, which is hundreds of milliseconds to seconds. That is a readable account-enumeration oracle for an unauthenticated caller, and the fact it discloses ("this address is an active manager") is worth more to a phisher than a raw address list. Two fixes exist and both cost something the ticket decided against: hand the send to the queue (reopens the ticket's own open question, which resolved to inline), or pad the handler to a fixed floor above p99 send time (a multi-second hold on an anonymous endpoint). Left as-is with the trade stated in the handler's docblock — your call.

The ticket's open question is answered inline, matching the verify and reset mail Managers.auth already builds with renderEmail, and keeping the throttle meaningful.

Manual verification

  1. On the preview, POST /api/managers/request-magic-link with your own manager address, then follow the emailed link — it should show a confirmation page, and its button should land you authenticated in /admin.
  2. curl that same emailed link, which is what a scanner does. It must answer 200 with a form and no Set-Cookie, and the link must still work afterwards.
  3. POST the request endpoint with an address no manager holds, and diff the response against the success case. Status and body must be byte-identical.
  4. GET /api/managers/me after signing in that way, at two locales, and confirm roles is the per-locale record rather than a flat array.
  5. Follow the same link a second time — it must be refused.
  6. Request a link with your address typed in a different case, and again with a trailing space. Both must deliver.
  7. Sign in as a manager whose Current Project is Sahaj Atlas, and confirm the mail carries Atlas branding rather than We Meditate's.
Detail

Every load-bearing assertion was watched fail at its defect's real site, per docs/rules/testing-reqs.md:

Assertion Defect reintroduced Went red
Uniform request-magic-link answer a 429 on throttle ✓
The 60-second throttle the window check removed ✓
A fresh request invalidates the outstanding link the claim equality removed ✓
setProject survives endpoints: replaced, not appended ✓
magicLinkIssuedAt is not hand-writable the field's update: () => false removed ✓
An unverified manager signs in _verified: true dropped from the burn ✓
A differently-cased address is found the schema's .toLowerCase() removed ✓
Only the named collections are wired the field dropped; one entry served; an unmatched slug materialised ✓
A collection's own endpoints survive endpoints: replaced, not appended ✓
Nothing is wired when the option is empty or disabled the guard removed ✓
The mail brands itself from the project it is given getEmailBrand(project) reverted to getEmailBrand() ✓
managersLogin resolves that project off the document the project resolver removed ✓
The plugin default is what sends for managers managersLogin given a generateEmailSubject of its own ✓
A scanner's GET spends nothing the GET wired back to the burn ✓
The page offers a POST form and nothing self-submitting the same ✓
A dead link is refused before the page is offered the GET's own token check removed ✓

The last three rows are the scanner defence (36e48f5). Reverting the whole thing — the emailed GET wired back to the burn, with no POST — turns eleven specs red, so the isolated form was used instead: the POST left in place and a second GET pointed at the same handler. Exactly the two new scanner assertions fail there, which is what proves they test the burn rather than the feature.

The wiring rows are tests/unit/login-plugin.spec.ts (0d12fac); the three mail rows are tests/unit/login-mail.spec.ts (522be0d). The wiring spec's unmatched-slug assertion was vacuous in its first form — folded against an empty config, it never reached the lookup it was written for, and passed with the defect present. It folds against a real collection now.

One assertion is pinned as a property rather than a mechanism, and says so in the spec: a link token presented as a session cookie is refused by two independent accidents of Payload's JWTAuthentication — the claim is userId not id, and there is no sid for the session check managers inherits. Measured: adding an id claim alone does not flip it. It is not vacuous — the cookie case above it reaches user.id through the same client and read path.

Why the confirmation page carries the token in the form's action. A custom Payload endpoint is handed no parsed form body — parseBody reads JSON, which a form submit does not send — so the POST handler reads req.query.token, exactly as the GET did. The URL is the one the email already delivered, so nothing new is exposed by it. page.ts sends Cache-Control: no-store, Referrer-Policy: no-referrer and X-Robots-Tag: noindex for the same reason the credential is in the URL at all.

tests/utils/restRequest.ts now returns {} for a body that is not JSON rather than throwing. The redeem route answers a browser with HTML, and raw is what the spec asserts against there.

What the review passes changed, beyond the slug. Both reads gained a bounded select; the email's "valid for" string derives from SIGNIN_TOKEN_TTL_MS rather than restating it (it would otherwise have silently lied after a TTL change); the send routes header text through emailSafeText, as six of the seven other senders do; and createAnonRestClient / createRestClientWithAuth joined tests/utils/restRequest.ts instead of the spec rebuilding handleEndpoints three times. The endpoints' Candidate shadow types are gone: a structural LoginDocument replaces them, since a shape tied to one collection's generated type would make every second collection a cast. managersLogin.isEligible still reads Manager['type'], so renaming that enum option upstream fails the typecheck rather than quietly admitting every manager.

LoginDocument and SessionDocument are not overlapping systems, which a thread asked. They narrow two different reads: the first is what the endpoints select, the second is what getFieldsToSign needs off createSession's own findByID — sessions, which the endpoints never select. Each docblock now names the other.

Declined review findings, with reasons. The invite half of token.ts has no production caller and three reviewers suggested dropping it — it is explicit ticket scope (manager-invite, 7 days) and an acceptance criterion, so it stays. hasSessionsField scans for the field rather than reading auth.useSessions / auth.disableLocalStrategy, because disableLocalStrategy: { enableFields: true } is a shape where the flags and the field disagree, and the flag reading would refuse a collection that does have sessions. The redeem route reads the account and then createSession reads it again: threading a pre-read document in would re-open the exact hazard that function's docblock exists to close (a caller supplying a select-narrowed doc silently drops a saveToJWT field), and sign-in is not a hot path. Neither write threads req: the link must be burned even if minting then fails, and a shared transaction would roll the burn back and leave the link live.

No email preview links. There is no scripts/preview-*-emails.ts covering manager auth mail, and SMTP_URL is unset here, so nothing could be posted to Mailpit. The template is asserted instead by the integration spec, which reads the rendered HTML back and extracts the link from it — the same shape manager-verification.int.spec.ts uses, and for the same reason: reading the token off the row would pass even if the template embedded no link at all.

One flake observed, then fixed. The first full pnpm test:int run failed user-submissions-review-lifecycle.int.spec.ts on an image-upload fixture (ValidationError: filename). staticDir is shared across suites, so two concurrent uploads read the same directory before either writes and land on the same -N suffix. Fixed in ebe812e by naming fixture uploads uniquely.

Not registered in the OpenAPI shim, deliberately: docs/rules/endpoints.md requires it for public, client-facing endpoints, and managers is admin-only and in no project. tests/unit/openapi-custom-endpoints.spec.ts asserts a fixed list, so nothing fails — confirmed rather than assumed.

Closes #837

🤖 Generated with Claude Code

https://claude.ai/code/session_01RhggSG55nFwfC3HyV9bPRb

…points

Adds `loginPlugin`: one hidden `magicLinkIssuedAt` timestamp plus the two
endpoints that trade an emailed link for an admin session. Passwords keep
working — this is a second way in, not a cut-over.

`session.ts` generalises past `managers`: `createSession(payload, slug, id)`
mints for any auth collection the plugin's options name, and refuses one
carrying no `sessions` field. `clients` is that case — `disableLocalStrategy`
means Payload adds neither `sessions` nor `email`, so a token minted for it
would authenticate nothing.

The two token kinds are separate JWT audiences, so an aged invitation cannot
be replayed as a sign-in. `magicLinkIssuedAt` carries three jobs at once: the
60-second throttle (the only in-app bound on per-account link volume, since
`rateLimitHook` is a no-op and the edge cannot see the email), the claim the
consume route matches exactly, and the clear that makes a link single-use.

`requestLink` answers identically for a link sent, an unknown address, an
inactive manager and a throttled repeat — any difference is an enumeration
oracle on an anonymous endpoint.

Refs #837

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015xud3n3UF2tPLDxiZmncZV
Fifteen integration assertions through the real REST pipeline, anonymously,
plus a unit spec pinning the two token audiences as a closed set against the
three kinds already in use.

Each load-bearing assertion was watched fail at the defect's real site: the
uniform `request-link` answer against a 429 on throttle, the throttle against
its removal, the claim equality against its removal, and the endpoint append
against a replacement that deletes `setProject`.

`createTestEnvironmentWithEmail` now returns its config, so a suite needing
both captured mail and `handleEndpoints` no longer has to choose.

Also documents the plugin-wired-endpoint split in docs/rules/endpoints.md.

Refs #837

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015xud3n3UF2tPLDxiZmncZV
Four independent review passes converged on the same defect: the endpoints
advertised a collection-agnostic slug parameter their bodies contradict. They
branch on `type === 'inactive'`, an enum only `managers` declares, send from
`MANAGER_EMAIL_FROM` with a manager-shaped template, and verify audiences named
`manager-signin` / `manager-invite`. A second collection would have got the
routes, a wrong predicate and the wrong branding.

They are now plain `Endpoint` constants over `'managers'`, like `setProject`
beside them and like `formsPlugin`'s `user-submissions` wiring. That removes
four `as never` casts and both hand-written shadow types — a `Candidate` widened
`type` to `string`, so `=== 'Inactive'` type-checked in the two places the
inactive check IS the gate. They are `Pick<Manager, …>` now.

`createSession` keeps its slug and its `sessions` guard: it is the piece a
second auth collection genuinely reuses.

Also from the review: both reads gain a bounded `select`; the email's "valid
for" string derives from `SIGNIN_TOKEN_TTL_MS` rather than restating it; the
send routes its header text through `emailSafeText`, as six of the seven other
senders do; `createAnonRestClient` joins `tests/utils/restRequest.ts` instead of
the spec rebuilding `handleEndpoints` three times.

Refs #837

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015xud3n3UF2tPLDxiZmncZV
From the branch security review. Self-access grants a manager update on their
own document, so the field's "requestLink is its only writer" was prose rather
than enforcement: a manager could re-arm or burn their own outstanding link,
or stamp a future instant and throttle their own sends forever. `update: () =>
false` matches the lock Payload puts on the `sessions` field beside it, and
both endpoints write through `overrideAccess: true`.

Also records the one hazard the review found and could not rule out by design:
these tokens share `payload.secret` with Payload's session JWTs, and
`JWTAuthentication` pins neither algorithm nor audience. A link token is
refused as a session credential by two independent accidents of that verifier —
the claim is `userId` not `id`, and there is no `sid`. Now asserted rather than
trusted; adding an `id` claim alone was measured not to flip it.

Refs #837

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015xud3n3UF2tPLDxiZmncZV
- `src/collections/AGENTS.md` — the Login plugin beside SEO and Form Builder:
  the field's three jobs, why both routes are anonymous, and that the plugin
  appends rather than replaces.
- `docs/rules/access.md` — all four localized-roles hooks fire on an auth
  RESPONSE, which is why the consume route redirects instead of returning a
  user. Any future route that mints its own session owes the same choice.
- `docs/rules/endpoints.md` — the plugin-wired-endpoint split, keyed on a
  literal slug.
- `tests/AGENTS.md` — `createAnonRestClient` / `createRestClientWithAuth`.

Refs #837

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

railway-app Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

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

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

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 23, 2026
@sydevs-bot

sydevs-bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running
CI fix 1

recent dispatches
  • 00:49Z address-review · attempt 1 · session · done
  • 00:49Z address-review · attempt 1 · session
  • 00:20Z address-review · attempt 1 · session · done
  • 00:20Z address-review · attempt 1 · session
  • 23:20Z address-review · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@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

The diff is the ticket's size and shape. Keying on the literal slug beats the collections option it replaced, the plugin appends rather than replaces, and nothing here is unasked-for.

Two gaps, both about who the routes let through. Managers.auth.verify is configured, so an unverified manager spends a link and lands on a cookie that authenticates nothing — precisely who #664's invite half exists for. The address lookup is a bare equality where every other path here normalises first.

Your timing oracle is real and I would leave it.

Findings

  • blocker — consumeLink.ts:80 unverified manager: link burned, session dead, no message.
  • should-fix — requestLink.ts:77 case-sensitive email lookup, hidden by the uniform answer.
  • consider — consumeLink.ts:51 a GET that burns the link; mail scanners prefetch.

Checked: both handlers and all of src/plugins/login/ whole; Managers.ts:22-60; signedToken.ts; requireActiveManager.ts:23; restRequest.ts:48; upsertUserByEmail.ts:26; all 17 specs; the doc diffs.

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


Generated by Claude Code

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 23, 2026
From the adversarial review on #847. `Managers.auth.verify` is configured, and
Payload's JWT strategy yields no user while `_verified` is false. Neither route
read the flag, so an unverified manager got the mail, `consume-link` burned the
link, minted a cookie and redirected to `/admin` — which bounced them to the
login form with no message, their one link spent and the 60-second throttle
refusing the obvious retry.

Setting the flag is the answer rather than refusing at `request-link`: following
a link delivered to the stored address is the same proof of ownership the verify
mail asks for, and #664's invited managers are unverified by definition.

Every fixture in the spec passed `_verified: true`, which is why the lane could
not see this. The new case builds an unverified manager and spends the cookie —
it fails with `user` undefined when the flag is not written.

Refs #837

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Rk89KqrRni8eWSqK7vqypB
From the adversarial review on #847. Payload's `email` base field lowercases and
trims on every write, so the stored column is normalised and the lookup's bare
equality was not: a manager typing `[email protected]` matched nothing.
Because the answer is deliberately identical to an unknown address, they got no
mail and no signal, every time they tried.

`upsertUserByEmail` and Payload's own `/login` both normalise before the same
shape of query. Trimming as well as lowercasing mirrors the stored value exactly,
so a pasted trailing space stops being a 400.

Refs #837

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Rk89KqrRni8eWSqK7vqypB
From the adversarial review on #847. Link-scanning mail security fetches every
URL in an inbound message, so a scanner can consume the link before the
recipient clicks, and the throttle then refuses the obvious retry. No machinery
here — the recipients' mail providers decide whether this is worth an
interstitial page, and that call is the reviewer's. The docblock records what to
check first when a manager reports an invalid link.

Refs #837

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Rk89KqrRni8eWSqK7vqypB
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-847 September 23, 2026 17:32 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed the adversarial review: three threads, three commits, pushed as b593218.

Adopted

  • blocker — consume-link now writes _verified: true with the burn. An unverified manager was spending a link on a cookie that authenticated nobody. 2002995
  • should-fix — the address lookup normalises. Payload lowercases and trims that column on every write. 5129cb2

Left open, for @Ardnived

  • consider — a mail scanner can spend a GET link. Recorded as the handler's first ⚠; the interstitial POST page is out of scope here. b593218

Both fixes were reintroduced at their real site and watched go red. Lean gate green, and 19 targeted integration specs pass.

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


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 23, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review September 23, 2026 17:41
@sydevs-bot
sydevs-bot requested a review from Ardnived September 23, 2026 17:41
Comment thread src/plugins/login/loginPlugin.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 23, 2026
Addresses both review threads on #847. The plugin took no `collections` option
and keyed on a literal `managers`; the endpoint definitions sat beside that one
collection while the plugin only wired them.

`loginPlugin({ collections: [...] })` now builds a `request-link` /
`consume-link` pair per entry, and both definitions moved into
`src/plugins/login/endpoints/` as factories — there is no single collection to
park them beside once more than one can be served.

The option is a list of configs, not of bare slugs, and that is the whole
difference between a knob and a footgun. Three things in these routes belong to
the collection, not the plugin: the eligibility predicate (`type === 'inactive'`
is a `managers` enum), the envelope sender, and the mail template. A bare slug
list would accept a second collection and mail it manager branding under a
predicate its schema has no field for. `LoginCollectionConfig` requires `mail`
and takes `isEligible`, `select` and `redirectTo`, so a second slug cannot be
added without supplying what makes it correct. `managersLogin` holds those
values beside Managers.

Token audiences stay `manager-signin` / `manager-invite`. Cross-collection
replay is already refused by the `collection` claim, which `consume-link` now
compares against its own configured slug, so renaming the audiences would churn
a pinned security constant to no effect.

`isEligible` is re-checked on consume as well as on request: an account
deactivated while a link was outstanding must not be able to spend it. That was
already true and stays true.

Behaviour for `managers` is unchanged — all 19 specs in
manager-magic-link.int.spec.ts pass untouched, as do login-session,
managers-access and role-based-access (85 more).

tests/unit/login-plugin.spec.ts is new: it folds the plugin by hand, before
sanitizeConfig, where `endpoints` is still undefined. Each of its six
assertions was watched fail at its defect's real site — replacing rather than
appending endpoints, dropping the field, throwing on an unnamed collection,
materialising one for an unmatched option slug, serving only the first entry,
and dropping the empty/disabled guard. The unmatched-slug assertion was vacuous
in its first form, passing against an empty config that never reached the
lookup, and is folded against a real collection now.

Refs #837

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019vpHpugPJ1hp7iaBXSiH2E
Both docs stated the rule this PR's review reversed. `docs/rules/endpoints.md`
said to key on the literal slug because a handler branching on a
collection-specific enum, sender or template cannot honour a slug parameter —
true, and now the reason the option carries those three as configuration rather
than the reason not to have one. The rule is restated as the choice it really
is: hard-code the target and say so, or pay for the promise a slug option makes.

`src/AGENTS.md` described the barrel stopping short of endpoints that live
beside their collection. They live in the plugin now, and the barrel still stops
short of them, for a different reason: loginPlugin is their only caller.

Refs #837

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019vpHpugPJ1hp7iaBXSiH2E
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 24, 2026
The two handlers are `requestMagicLink` and `redeemMagicLink`; their routes
were still `/request-link` and `/consume-link`. @Ardnived confirmed no links
have been delivered, so nothing outstanding carries the old paths, and #837
names the request path only as a placeholder rather than pinning it.

`REQUEST_LINK_PATH` and `CONSUME_LINK_PATH` follow, as does the integration
spec's `CONSUME_PATH`, which otherwise named a redeem route "consume".

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0164fYKRinsznYoRRuXrnoTA
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-847 September 24, 2026 00:25 Destroyed
@sydevs-bot sydevs-bot changed the title feat(auth): the login plugin, with magic-link request and consume endpoints feat(auth): the login plugin, with magic-link request and redeem endpoints Sep 24, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Fifth round — the route paths, pushed as 0ace32d.

Adopted

⚠ Three earlier rounds defended the old paths by claiming #837 published them. It does not — its checklist spells the route <request path>, a placeholder. That claim was wrong each time I made it.

Settled

Still yours — inline send versus a job, a bare slug list, the timing oracle, and the GET that burns a link.

Lean gate green. 19 magic-link integration specs pass.

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


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. awaiting labels Sep 24, 2026
Link-scanning mail security (Defender Safe Links, Proofpoint) issues a GET
on every URL in an inbound message before its recipient sees it. The redeem
route was a GET that cleared `magicLinkIssuedAt`, so a scanner spent the
manager's one use, and `request-magic-link`'s 60-second throttle then
refused the obvious retry: no session and no second mail.

The burn moves to POST. A second handler holds GET on the same path and
renders a plain form that submits it. Scanners do not POST and do not
click, so the link survives the scan and its owner still spends it in one
action. The form carries no script and no refresh, which is the whole
defence — anything that submitted it automatically would restore the
hazard.

The GET verifies the token so a dead link reads as a sentence, and that
check touches no document: a scanner's fetch stays free of consequence.
Both handlers answer a browser now, so their refusals are HTML pages
rather than error envelopes.

`tests/unit/login-plugin.spec.ts` asserts `<method> <path>` rather than the
path alone, because which verb each handler answers is now the security
property. All three new assertions were watched fail at their real defect
sites: the GET wired to the burn, and the page offered without verifying.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RhggSG55nFwfC3HyV9bPRb
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-847 September 24, 2026 01:06 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Sixth round — the mail-scanner hazard, pushed as 36e48f5.

Adopted

  • A GET that burns the link — the burn is a POST now, behind a confirmation page the GET renders. Scanners fetch links but neither POST nor click, so a scan costs the recipient nothing. The page carries no script and no refresh; the spec asserts that, because anything self-submitting would restore the hazard.

Settled

Still yours — a bare slug list, the timing oracle, and the project branding that contradicts #483.

Lean gate green. Full pnpm test:int green: 85 files, 1406 tests. Three new assertions watched fail at their real sites.

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


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. awaiting labels Sep 24, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Sep 24, 2026
Merged via the queue into main with commit a529e86 Sep 24, 2026
25 of 26 checks passed
@sydevs-bot
sydevs-bot deleted the claude/feat-837-magic-link-login branch September 24, 2026 04:32
@sydevs-bot sydevs-bot moved this from Revising to Done in SYDevelopers Technical Roadmap Sep 24, 2026
sydevs-bot pushed a commit that referenced this pull request Sep 25, 2026
The GET on /redeem-magic-link existed only to render HTML, which is what
made the plugin own two pages in a visual language nothing else on the site
speaks. Moving the address instead of the method keeps the whole scanner
defence: the mail now points at `requestPagePath`'s own `(frontend)` page,
which reads the token and writes nothing, and the burn stays behind that
page's form on a method no scanner uses.

So `page.ts` and `confirmMagicLink` both go, `requestPagePath` becomes
required — it is the address in the mail — and every refusal redirects to
`?error=expired|invalid`, the spelling #838 asked for and #847 dropped.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018HjG73fjLEx2FhsBgWsMXf
Ardnived added a commit that referenced this pull request Sep 25, 2026
…can post links (#854)

* feat(email): send preview mail over Mailpit's HTTP API, so a routine can post links

A Claude routine reaches the network only through an HTTPS proxy, so the
preview scripts' SMTP send to Mailpit's TCP proxy timed out there (#807) and
no loop PR could carry an email preview link (#847, #853).

The capture transport now posts to Mailpit's `POST /api/v1/send` instead,
authenticated with a send-only `MAILPIT_SEND_AUTH` (Mailpit's
`MP_SEND_API_AUTH`), falling back to `MAILPIT_UI_AUTH` while no send
credential is configured. The scripts no longer read `SMTP_URL`; the app
still sends through it.

Also records where previews get `SMTP_URL` from: production's service, where
it is inert, since Railway copies production's variables into every PR
environment.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* refactor(email): send preview mail with the Mailpit login, not a send-only one

Mailpit holds nothing a read login could leak: a preview's database has no
production rows, and production mail goes to Resend. So one credential,
MAILPIT_UI_AUTH, serves the scripts, the reviewer and the routine, which can
now open its own previews too.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-847 — 618d6dfb Deployed Sep 24, 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): the login plugin, with magic-link request and consume endpoints

3 participants