Skip to content

feat(clerk-js): Signal reset password flow #6520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dstaley
Copy link
Member

@dstaley dstaley commented Aug 11, 2025

Description

This PR introduces the reset password flow for our new Signals-based API, which is experimental and not intended for public use yet.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • New Features

    • Introduced an experimental password reset via email code flow in the sign-in experience.
    • Users can request a reset code, verify it, and set a new password.
    • Optionally sign out of other active sessions after resetting the password.
  • Chores

    • Bumped minor versions of related packages with a changelog note for the experimental reset password flow.

Copy link

changeset-bot bot commented Aug 11, 2025

🦋 Changeset detected

Latest commit: f6b9e17

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
@clerk/clerk-js Minor
@clerk/types Minor
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/shared Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/themes Patch
@clerk/vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Aug 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 11, 2025 6:53pm

Copy link

pkg-pr-new bot commented Aug 11, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6520

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6520

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6520

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6520

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6520

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6520

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6520

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6520

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6520

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6520

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6520

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6520

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6520

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6520

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6520

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6520

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6520

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6520

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6520

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6520

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6520

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6520

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6520

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6520

commit: f6b9e17

Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

📝 Walkthrough

Walkthrough

  • Adds a changeset bumping minor versions of @clerk/clerk-js and @clerk/types with note “[Experimental] Signals reset password flow.”
  • In clerk-js SignInFuture, introduces resetPasswordEmailCode with methods: sendCode, verifyCode, submitPassword. Implements internal handlers:
    • sendResetPasswordEmailCode: finds reset_password_email_code factor, prepares first factor.
    • verifyResetPasswordEmailCode: attempts first factor with code.
    • submitResetPassword: posts new password and optional signOutOfOtherSessions.
  • Emits resource:error events on start (null) and on error.
  • In types, extends SignInFutureResource with resetPasswordEmailCode definitions matching the three methods and their signatures.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
.changeset/wise-hornets-sneeze.md (1)

6-6: Nit: Make the changelog entry a bit more descriptive.

Consider briefly listing the new experimental API surface (e.g., SignInFuture.resetPasswordEmailCode with sendCode/verifyCode/submitPassword) to help consumers understand the scope from the changelog alone.

Happy to propose a concise wording if helpful.

packages/types/src/signIn.ts (1)

136-140: Add JSDoc and experimental marker on the new future API.

Document the new resetPasswordEmailCode group and its methods, and mark as experimental to match runtime code comments. This also satisfies the project guideline “All public APIs must be documented with JSDoc.”

Proposed addition (outside this hunk, placed above line 136):

/**
 * @experimental This experimental API is subject to change.
 * Reset password flow using an email code for the Signals-based API.
 *
 * Usage:
 * - sendCode(): prepares the reset password email_code factor and sends a code to the user's email.
 * - verifyCode({ code }): attempts the first factor with the provided code.
 * - submitPassword({ password, signOutOfOtherSessions? }): completes the reset with a new password.
 */

Optional: Introduce a small helper type for consistency with the rest of the interface:

type FutureResult = { error: unknown };

Then use Promise<FutureResult> across methods to reduce repetition.

packages/clerk-js/src/core/resources/SignIn.ts (2)

500-505: LGTM on API surface; add JSDoc and experimental marker.

The property mapping mirrors emailCode and reads well. Add a JSDoc block indicating experimental status to match the type-level addition and project docs guidelines.


512-538: Align error handling with existing error helpers for consistency.

  • Replace generic new Error('Cannot reset password without a sign in.') with a project error helper (similar to clerkVerifyEmailAddressCalledBeforeCreate('SignIn')) for consistency and better DX.
  • Same for “Reset password email code factor not found” (consider a dedicated helper).

This keeps error messages standardized and translatable, and aligns with guidelines on meaningful error messages and proper logging.

If you prefer to keep inline errors, at least add recovery suggestions to the messages (e.g., “Call create({ identifier }) first and ensure the reset_password_email_code factor is supported.”).

Also, please add tests covering:

  • missing id (precondition)
  • missing factor
  • happy path calling prepare_first_factor with the expected body
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d93b0ed and f6b9e17.

📒 Files selected for processing (3)
  • .changeset/wise-hornets-sneeze.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (1 hunks)
  • packages/types/src/signIn.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/types/src/signIn.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/types/src/signIn.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/types/src/signIn.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/types/src/signIn.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/types/src/signIn.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/types/src/signIn.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
**/*

⚙️ CodeRabbit Configuration File

If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

Files:

  • packages/types/src/signIn.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
.changeset/**

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/wise-hornets-sneeze.md
🧬 Code Graph Analysis (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
packages/clerk-js/src/core/events.ts (1)
  • eventBus (28-28)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
.changeset/wise-hornets-sneeze.md (1)

2-4: Changeset version bumps look correct for an experimental feature.

Minor bumps for @clerk/clerk-js and @clerk/types align with adding new experimental API surface.

Comment on lines +540 to +553
async verifyResetPasswordEmailCode({ code }: { code: string }): Promise<{ error: unknown }> {
eventBus.emit('resource:error', { resource: this.resource, error: null });
try {
await this.resource.__internal_basePost({
body: { code, strategy: 'reset_password_email_code' },
action: 'attempt_first_factor',
});
} catch (err: unknown) {
eventBus.emit('resource:error', { resource: this.resource, error: err });
return { error: err };
}

return { error: null };
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Validate input before network call (verification code).

Avoid a roundtrip when the code is empty/whitespace. Emit and return an error immediately.

-  async verifyResetPasswordEmailCode({ code }: { code: string }): Promise<{ error: unknown }> {
-    eventBus.emit('resource:error', { resource: this.resource, error: null });
+  async verifyResetPasswordEmailCode({ code }: { code: string }): Promise<{ error: unknown }> {
+    if (!code?.trim()) {
+      const err = new Error('Verification code is required');
+      eventBus.emit('resource:error', { resource: this.resource, error: err });
+      return { error: err };
+    }
+    eventBus.emit('resource:error', { resource: this.resource, error: null });
     try {
       await this.resource.__internal_basePost({
         body: { code, strategy: 'reset_password_email_code' },
         action: 'attempt_first_factor',
       });

Please add a unit test for the empty/whitespace code input case.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async verifyResetPasswordEmailCode({ code }: { code: string }): Promise<{ error: unknown }> {
eventBus.emit('resource:error', { resource: this.resource, error: null });
try {
await this.resource.__internal_basePost({
body: { code, strategy: 'reset_password_email_code' },
action: 'attempt_first_factor',
});
} catch (err: unknown) {
eventBus.emit('resource:error', { resource: this.resource, error: err });
return { error: err };
}
return { error: null };
}
async verifyResetPasswordEmailCode({ code }: { code: string }): Promise<{ error: unknown }> {
if (!code?.trim()) {
const err = new Error('Verification code is required');
eventBus.emit('resource:error', { resource: this.resource, error: err });
return { error: err };
}
eventBus.emit('resource:error', { resource: this.resource, error: null });
try {
await this.resource.__internal_basePost({
body: { code, strategy: 'reset_password_email_code' },
action: 'attempt_first_factor',
});
} catch (err: unknown) {
eventBus.emit('resource:error', { resource: this.resource, error: err });
return { error: err };
}
return { error: null };
}
🤖 Prompt for AI Agents
In packages/clerk-js/src/core/resources/SignIn.ts around lines 540 to 553, add
input validation to immediately handle empty or all-whitespace verification
codes: trim the incoming code and if it's empty, create an Error (e.g. new
Error('verification code is required')), emit eventBus.emit('resource:error', {
resource: this.resource, error }), and return { error } without calling
__internal_basePost. Update/ add unit tests to cover both empty string and
whitespace-only inputs: assert that an error is returned, eventBus emitted with
that error, and __internal_basePost was not invoked.

Comment on lines +555 to +574
async submitResetPassword({
password,
signOutOfOtherSessions = true,
}: {
password: string;
signOutOfOtherSessions?: boolean;
}): Promise<{ error: unknown }> {
eventBus.emit('resource:error', { resource: this.resource, error: null });
try {
await this.resource.__internal_basePost({
body: { password, signOutOfOtherSessions },
action: 'reset_password',
});
} catch (err: unknown) {
eventBus.emit('resource:error', { resource: this.resource, error: err });
return { error: err };
}

return { error: null };
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Validate password input before network call; optionally pre-check policy.

  • Ensure password is non-empty before sending the request.
  • Optionally, call the existing validatePassword (policy pre-check) to provide earlier feedback.
   async submitResetPassword({
     password,
     signOutOfOtherSessions = true,
   }: {
     password: string;
     signOutOfOtherSessions?: boolean;
   }): Promise<{ error: unknown }> {
-    eventBus.emit('resource:error', { resource: this.resource, error: null });
+    if (!password) {
+      const err = new Error('Password is required');
+      eventBus.emit('resource:error', { resource: this.resource, error: err });
+      return { error: err };
+    }
+    eventBus.emit('resource:error', { resource: this.resource, error: null });
     try {
       await this.resource.__internal_basePost({
         body: { password, signOutOfOtherSessions },
         action: 'reset_password',
       });

Consider tests for:

  • empty password
  • successful submission with default signOutOfOtherSessions
  • explicit signOutOfOtherSessions: false
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async submitResetPassword({
password,
signOutOfOtherSessions = true,
}: {
password: string;
signOutOfOtherSessions?: boolean;
}): Promise<{ error: unknown }> {
eventBus.emit('resource:error', { resource: this.resource, error: null });
try {
await this.resource.__internal_basePost({
body: { password, signOutOfOtherSessions },
action: 'reset_password',
});
} catch (err: unknown) {
eventBus.emit('resource:error', { resource: this.resource, error: err });
return { error: err };
}
return { error: null };
}
async submitResetPassword({
password,
signOutOfOtherSessions = true,
}: {
password: string;
signOutOfOtherSessions?: boolean;
}): Promise<{ error: unknown }> {
if (!password) {
const err = new Error('Password is required');
eventBus.emit('resource:error', { resource: this.resource, error: err });
return { error: err };
}
eventBus.emit('resource:error', { resource: this.resource, error: null });
try {
await this.resource.__internal_basePost({
body: { password, signOutOfOtherSessions },
action: 'reset_password',
});
} catch (err: unknown) {
eventBus.emit('resource:error', { resource: this.resource, error: err });
return { error: err };
}
return { error: null };
}
🤖 Prompt for AI Agents
In packages/clerk-js/src/core/resources/SignIn.ts around lines 555 to 574, the
submitResetPassword method currently sends the network request without
validating the password; update it to first check that password is a non-empty
string and return an immediate error if empty, and optionally invoke the
existing validatePassword (policy pre-check) before the network call to produce
early, client-side feedback; preserve existing eventBus.error emissions on
failure and ensure returned error shape stays { error: unknown }; add unit tests
for empty password, successful submission with default signOutOfOtherSessions,
and explicit signOutOfOtherSessions: false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants