Skip to content

fix(auth): register client email verification mutation - #423

Merged
omegascorp merged 5 commits into
modelence:mainfrom
NilotpalK:fix/client-email-verification-421
Oct 28, 2026
Merged

omegascorp merged 5 commits into
modelence:mainfrom
NilotpalK:fix/client-email-verification-421

Conversation

@NilotpalK

@NilotpalK NilotpalK commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

verifyEmail({ token }) always rejects with Method with name '_system.user.verifyEmail' is not defined. The documented client helper exists, but its server mutation is missing.

Register the mutation and reuse verifyEmailToken for the existing expiry, account-status, address-update, and token-consumption checks. Invoke the email-verification success/error hooks with session: null and the caller's connection information, and propagate errors to the client.

The mutation only verifies the address: it does not create a session, replace the caller's account, or set an auth cookie. The existing emailed-link route keeps its behavior. Document this distinction in the manual-verification guide.

Fixes #421.

The documentation workflow also type-checks the existing Resend test, which imports Vitest. Add the missing dev dependency, update its lockfile, and expose npm test so a clean install can run the test and generate documentation.

Validation:

  • Clean Resend install, its attachment regression test, Resend type checking/build, full TypeDoc generation, unchanged API Reference navigation, and all 187 documentation content files' internal links pass.

  • Added 11 regression cases through the real user module and server method registry. Successful cases call the real client helper using the built-in in-process transport; database operations are stubbed. Coverage includes anonymous and authenticated callers, unknown/expired/reused tokens, malformed input, disabled/deleted accounts, hooks, and unchanged caller sessions.

  • The new cases reproduced the missing-method failure before the fix and pass afterward. All 579 auth tests pass, including the existing emailed-link tests.

  • Lint, build, importing the built server module with Node.js, and Prettier for changed TypeScript files pass.

  • TypeScript type checking, full TypeDoc generation, API Reference navigation sync, and internal documentation link checks pass. The CI fixture type mismatch is corrected; all 58 focused auth/client tests pass.

  • Full suite: 1,450 passed, 10 failed. The failures are identical to the unchanged-main baseline in authCache.test.ts (1), dev.test.ts (1), deploySpec.test.ts (1), and source.test.ts (7): Windows file modes/path separators, symlink permissions, and missing unzip.

  • The full formatting check passes with --end-of-line auto; the default check flags existing CRLF files in this Windows checkout.


Note

Medium Risk
Touches authentication email verification and session semantics; behavior change for any code that expected user data from verifyEmail, but the mutation path is intentionally sessionless and is well covered by new tests.

Overview
Registers the missing _system.user.verifyEmail server mutation so the documented client verifyEmail({ token }) helper works instead of failing with “method not defined.”

The new handleVerifyEmailMutation reuses verifyEmailToken for the same validation and DB updates as the emailed-link GET route, but does not create a session, set an auth cookie, or alter the caller’s existing session. Success and error hooks run with session: null and the caller’s connection info; the client method’s return type is now void.

Docs under manual verification explain this vs the default link flow (which still signs the user in). Regression tests cover anonymous/authenticated callers, token edge cases, hooks, and session isolation. @modelence/resend adds a vitest dev dependency and test script (lockfile update only).

Reviewed by Cursor Bugbot for commit 479ab9d. Bugbot is set up for automated code reviews on this repo. Configure here.

@NilotpalK
NilotpalK requested a review from omegascorp as a code owner October 19, 2026 20:40
@omegascorp

Copy link
Copy Markdown
Collaborator

Thanks for this. The client verifyEmail helper has been broken since it was added, so this fix is needed. Fixing it is better than removing the export: a POST-based verify gives apps a way around email link scanners that use up the token by fetching the GET link before the user clicks.

Reusing verifyEmailToken and not creating a session both look right. Logging in whoever holds a token, or replacing a logged-in caller's session, would be a security problem. The tests cover the flow well.

A few small things before merging:

  1. Session passed to the hook. If user A is logged in and submits user B's token, onAfterEmailVerification receives user: B with A's session. Hook code that assumes session.userId === user._id would then act on the wrong account. The link route passes session: null. Could we do the same here for consistency? If you want to keep the caller's session, please say in the docs that it may belong to a different user than the one verified.

  2. Client return type. verifyEmail in src/auth/client/index.ts still calls callMethod<{ user: RawUserData }>, but the mutation returns nothing. Please change it to callMethod<void> (or similar) so the type matches.

  3. Docs: where the token comes from. The emailed link always goes to /api/_internal/auth/verify-email?token=…, so a client page never receives a token by default. One sentence explaining that manual verification needs a custom verification.template linking to your own page (which reads token and calls verifyEmail) would make this section usable.

  4. Optional: guard test. As the issue suggested, a test that every _system.user.* method the client calls is registered on the server would catch this kind of bug in future. It's fine as a follow-up.

@NilotpalK

NilotpalK commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Updated in c6ede31: both hooks receive session: null, the client call uses callMethod<void>, and the docs explain how a custom template sends the token to your own verification page.

The docs failure is also fixed in 479ab9d by adding the missing Vitest dependency and test script to Resend. After syncing with main, all 579 auth tests, the Resend test, TypeScript, lint, build, and full docs checks pass locally. The full suite has 1,450 passes and the same 10 Windows failures. CI Build and Bugbot passed. Every documentation step, including TypeDoc, navigation sync, and internal links, passed too; GitHub still reports the overall docs job as in progress.

@omegascorp omegascorp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you, approved

@omegascorp omegascorp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, approved

@omegascorp
omegascorp merged commit e678668 into modelence:main Oct 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client verifyEmail() always fails: '_system.user.verifyEmail' is not defined

2 participants