- 
                Notifications
    You must be signed in to change notification settings 
- Fork 403
feat(clerk-js, types): Add clientTrustState and untrustedFirstFactors… #7096
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
… to Client and SignIn resources - Trusted users automatically see password - Untrusted users automatically don't see password - Added Expo dummy data.
| 🦋 Changeset detectedLatest commit: 72ddfdc The changes in this PR will be included in the next version bump. 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 GitHub. 
 | 
| WalkthroughThis change introduces fraud protection support by adding two new fields across the Clerk packages:  Changes
 Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 
 Poem
 Pre-merge checks and finishing touches❌ Failed checks (1 warning)
 ✅ Passed checks (2 passed)
 ✨ Finishing touches
 🧪 Generate unit tests (beta)
 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment  | 
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.
🚀 Just a small change for clientTrustState/client_trust_state.
…tors to Client and SignIn resources for fraud protection
… and related interfaces
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: 0
🧹 Nitpick comments (10)
packages/clerk-js/src/test/core-fixtures.ts (1)
211-211: Good defaulting to an empty arrayDefaulting
untrusted_first_factorsto[]avoids undefined in snapshots/tests. Consider doing the same forsupported_first_factorsfor consistency in fixtures to reduce snapshot churn.Example change outside this hunk:
- supported_first_factors: signInParams.supported_first_factors, + supported_first_factors: signInParams.supported_first_factors || [],packages/types/src/client.ts (1)
23-23: Optional clientTrustState aligns with omission semanticsMaking
clientTrustStateoptional matches “omit when unknown”. Please add a short JSDoc since this is a public API.Suggested doc:
lastAuthenticationStrategy: LastAuthenticationStrategy | null; - clientTrustState?: ClientTrustState; + /** + * Trust classification for this client; omitted when unknown. + * Values: 'new' | 'known' | 'pending'. + */ + clientTrustState?: ClientTrustState;.changeset/client-trust-state.md (1)
1-7: Changeset looks right for a minor bumpMessage is clear. Consider noting omission semantics explicitly: “
client_trust_stateomitted when unknown;untrusted_first_factorspresent but often empty.”packages/clerk-js/src/core/resources/SignIn.ts (3)
106-107: Public field: add JSDoc and clarify null vs [] semanticsAdd a brief JSDoc describing when
untrustedFirstFactorsisnullvs[]for consumers.Example:
- untrustedFirstFactors: SignInFirstFactor[] | null = []; + /** + * First factors the backend marked untrusted for this client. + * null: not provided; []: provided but empty. + */ + untrustedFirstFactors: SignInFirstFactor[] | null = [];
531-532: Avoid undefined in fromJSONIf the backend omits the field,
deepSnakeToCamel(undefined)yieldsundefinedand overrides your default. Coalesce tonullto maintain a stable tri-state (array | null) and avoid undefined at runtime.- this.untrustedFirstFactors = deepSnakeToCamel(data.untrusted_first_factors) as SignInFirstFactor[] | null; + this.untrustedFirstFactors = + (deepSnakeToCamel(data.untrusted_first_factors) as SignInFirstFactor[] | null) ?? null;
550-551: Snapshot should not emit undefinedCoalesce to
nullso snapshots never containundefined.- untrusted_first_factors: deepCamelToSnake(this.untrustedFirstFactors), + untrusted_first_factors: deepCamelToSnake(this.untrustedFirstFactors ?? null),packages/types/src/signIn.ts (1)
44-45: Add JSDoc for new public APIPlease document
untrustedFirstFactorsusage for SDK consumers (e.g., “factors disallowed for this client by trust signals”).- untrustedFirstFactors: SignInFirstFactor[] | null; + /** + * First factors that are not allowed for this client due to trust evaluation. + */ + untrustedFirstFactors: SignInFirstFactor[] | null;packages/types/src/json.ts (1)
105-106: Type addition looks good; add a brief docAdd a one-line comment to clarify intended states and usage.
-export type ClientTrustState = 'new' | 'known' | 'pending'; +// Trust classification for a client, used by setup vs unlock flows. +export type ClientTrustState = 'new' | 'known' | 'pending';packages/expo/src/cache/dummy-data/client-resource.ts (1)
95-96: Dummy data parityAdding
untrusted_first_factors: []is good. Consider also includingclient_trust_state: nullat the top-level to mirror the new type (optional, but helps parity in snapshots/demos).Example:
last_authentication_strategy: null, + client_trust_state: null, created_at: new Date().getTime(),packages/clerk-js/src/core/resources/Client.ts (1)
30-30: Consider adding JSDoc and simplifying the type declaration.The property declaration has minor refinement opportunities:
Missing JSDoc: The similar property
lastAuthenticationStrategy(line 28) includes JSDoc documentation. For consistency and API clarity, consider documenting this public property.
Type redundancy: The optional marker
?already makes thisClientTrustState | undefined, so the explicit| undefinedand initialization toundefinedare redundant.Consider this refinement:
+ /** Client trust state for fraud protection; undefined when not yet determined by the backend. */ - clientTrustState?: ClientTrustState | undefined = undefined; + clientTrustState?: ClientTrustState;As per coding guidelines
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (9)
- .changeset/client-trust-state.md(1 hunks)
- packages/clerk-js/src/core/resources/Client.ts(5 hunks)
- packages/clerk-js/src/core/resources/SignIn.ts(3 hunks)
- packages/clerk-js/src/test/core-fixtures.ts(1 hunks)
- packages/expo/src/cache/dummy-data/client-resource.ts(1 hunks)
- packages/types/src/client.ts(2 hunks)
- packages/types/src/json.ts(2 hunks)
- packages/types/src/signIn.ts(2 hunks)
- packages/types/src/snapshots.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{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/expo/src/cache/dummy-data/client-resource.ts
- packages/types/src/json.ts
- packages/types/src/signIn.ts
- packages/clerk-js/src/core/resources/SignIn.ts
- packages/clerk-js/src/test/core-fixtures.ts
- packages/types/src/snapshots.ts
- packages/clerk-js/src/core/resources/Client.ts
- packages/types/src/client.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/expo/src/cache/dummy-data/client-resource.ts
- packages/types/src/json.ts
- packages/types/src/signIn.ts
- packages/clerk-js/src/core/resources/SignIn.ts
- packages/clerk-js/src/test/core-fixtures.ts
- packages/types/src/snapshots.ts
- packages/clerk-js/src/core/resources/Client.ts
- packages/types/src/client.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
- packages/expo/src/cache/dummy-data/client-resource.ts
- packages/types/src/json.ts
- packages/types/src/signIn.ts
- packages/clerk-js/src/core/resources/SignIn.ts
- packages/clerk-js/src/test/core-fixtures.ts
- packages/types/src/snapshots.ts
- packages/clerk-js/src/core/resources/Client.ts
- packages/types/src/client.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
- packages/expo/src/cache/dummy-data/client-resource.ts
- packages/types/src/json.ts
- packages/types/src/signIn.ts
- packages/clerk-js/src/core/resources/SignIn.ts
- packages/clerk-js/src/test/core-fixtures.ts
- packages/types/src/snapshots.ts
- packages/clerk-js/src/core/resources/Client.ts
- packages/types/src/client.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
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor 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 assertionsfor literal types:as const
Usesatisfiesoperator 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 ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor 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/expo/src/cache/dummy-data/client-resource.ts
- packages/types/src/json.ts
- packages/types/src/signIn.ts
- packages/clerk-js/src/core/resources/SignIn.ts
- packages/clerk-js/src/test/core-fixtures.ts
- packages/types/src/snapshots.ts
- packages/clerk-js/src/core/resources/Client.ts
- packages/types/src/client.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/expo/src/cache/dummy-data/client-resource.ts
- packages/types/src/json.ts
- packages/types/src/signIn.ts
- packages/clerk-js/src/core/resources/SignIn.ts
- packages/clerk-js/src/test/core-fixtures.ts
- packages/types/src/snapshots.ts
- packages/clerk-js/src/core/resources/Client.ts
- packages/types/src/client.ts
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
- .changeset/client-trust-state.md
🧬 Code graph analysis (5)
packages/types/src/signIn.ts (2)
packages/types/src/signInCommon.ts (1)
SignInFirstFactor(74-85)packages/types/src/json.ts (1)
SignInFirstFactorJSON(553-553)
packages/clerk-js/src/core/resources/SignIn.ts (2)
packages/types/src/signInCommon.ts (1)
SignInFirstFactor(74-85)packages/shared/src/underscore.ts (2)
deepSnakeToCamel(111-111)
deepCamelToSnake(102-102)
packages/types/src/snapshots.ts (2)
packages/types/src/utils.ts (1)
Nullable(40-42)packages/types/src/signIn.ts (1)
SignInJSON(94-110)
packages/clerk-js/src/core/resources/Client.ts (1)
packages/types/src/json.ts (1)
ClientTrustState(105-105)
packages/types/src/client.ts (1)
packages/types/src/json.ts (1)
ClientTrustState(105-105)
⏰ 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). (2)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (7)
packages/types/src/signIn.ts (1)
105-106: Confirm server contract: optional vs required
untrusted_first_factorsis modeled as required here, but the backend may omit it. If omission is possible, mark it optional (?:) to match wire shape, or ensure backend always sends[]. Please verify with the backend PR.If it can be omitted, change:
- untrusted_first_factors: SignInFirstFactorJSON[]; + untrusted_first_factors?: SignInFirstFactorJSON[];packages/types/src/json.ts (1)
116-117: Optional client_trust_state is appropriateOptionality reflects omission when unknown—LGTM.
packages/types/src/snapshots.ts (1)
38-41: Snapshot type updated correctlyIncluding
untrusted_first_factorsin the nullable set keeps snapshot shapes stable—LGTM.packages/clerk-js/src/core/resources/Client.ts (4)
6-6: LGTM!The import is correctly added alongside related types from
@clerk/types.
91-91: LGTM!The reset is consistent with the property's default value and follows the pattern of other properties in the destroy method.
141-141: LGTM!The assignment correctly deserializes the field from JSON, with TypeScript ensuring type safety.
160-160: No changes needed—the conditional serialization is correct.The conditional spread for
clientTrustStateis intentional and follows established patterns. The key difference fromlastAuthenticationStrategyis thatclientTrustStateis declared as an optional property (clientTrustState?: ClientTrustState | undefined), whereaslastAuthenticationStrategyis a required property that defaults tonull. The conditional spread correctly omits the field whenclientTrustStateis undefined, matching how optional fields should be serialized. The deserialization at line 141 mirrors this by directly assigningdata.client_trust_state, preserving the field's optional semantics.
Added
client_trust_stateanduntrusted_first_factorsfields to Client and SignIn resources to support the backend's Setup vs Unlock fraud protection feature.supported_first_factorssupported_first_factorsand moved tountrusted_first_factorsDescription
This PR adds type definitions and serialization support for two new fields coming from FAPI:
client_trust_state: A string enum ('new' | 'known' | 'pending') that indicates whether the backend trusts this client based on whether the user has had a session on this client before.untrusted_first_factors: An array of sign-in factors that are not allowed for this client (e.g., password for new/untrusted clients).How It Works
The backend (clerk_go PR #14403) handles all the filtering logic:
user_clientstableclient_trust_state = 'known'): password goes insupported_first_factorsclient_trust_state = 'new'or'pending'): password is excluded fromsupported_first_factorsand placed inuntrusted_first_factorsThe frontend changes are purely additive:
supported_first_factors, which the backend now filters appropriatelyTesting
pnpm --filter @clerk/types buildpnpm --filter @clerk/clerk-js buildpnpm testtom/setup-v-unlock-initialis deployed or built locally, then verify:Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
Release Notes