-
Notifications
You must be signed in to change notification settings - Fork 371
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: f6b9e17 The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
📝 WalkthroughWalkthrough
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15–20 minutes 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 toclerkVerifyEmailAddressCalledBeforeCreate('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
📒 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
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
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
Useconst assertions
for literal types:as const
Usesatisfies
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 ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
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.
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 }; | ||
} |
There was a problem hiding this comment.
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.
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.
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 }; | ||
} |
There was a problem hiding this comment.
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.
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.
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.Type of change
Summary by CodeRabbit
New Features
Chores