Skip to content

Commit ea65d39

Browse files
feat(clerk-js, types): Add clientTrustState and untrustedFirstFactors… (#7096)
Co-authored-by: Tom Milewski <me@tm.codes>
1 parent 85b5acc commit ea65d39

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

.changeset/client-trust-state.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/shared': minor
3+
'@clerk/clerk-js': minor
4+
---
5+
6+
Adds `client_trust_state` field to Client and SignIn resources to support new fraud protection feature.

packages/clerk-js/src/core/resources/Client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
ClientJSON,
44
ClientJSONSnapshot,
55
ClientResource,
6+
ClientTrustState,
67
LastAuthenticationStrategy,
78
SignedInSessionResource,
89
SignInResource,
@@ -26,6 +27,7 @@ export class Client extends BaseResource implements ClientResource {
2627
cookieExpiresAt: Date | null = null;
2728
/** Last authentication strategy used by this client; `null` when unknown/disabled. */
2829
lastAuthenticationStrategy: LastAuthenticationStrategy | null = null;
30+
clientTrustState?: ClientTrustState = undefined;
2931
createdAt: Date | null = null;
3032
updatedAt: Date | null = null;
3133

@@ -86,6 +88,7 @@ export class Client extends BaseResource implements ClientResource {
8688
this.signIn = new SignIn(null);
8789
this.lastActiveSessionId = null;
8890
this.lastAuthenticationStrategy = null;
91+
this.clientTrustState = undefined;
8992
this.cookieExpiresAt = null;
9093
this.createdAt = null;
9194
this.updatedAt = null;
@@ -135,6 +138,7 @@ export class Client extends BaseResource implements ClientResource {
135138
this.captchaBypass = data.captcha_bypass || false;
136139
this.cookieExpiresAt = data.cookie_expires_at ? unixEpochToDate(data.cookie_expires_at) : null;
137140
this.lastAuthenticationStrategy = data.last_authentication_strategy || null;
141+
this.clientTrustState = data.client_trust_state;
138142
this.createdAt = unixEpochToDate(data.created_at || undefined);
139143
this.updatedAt = unixEpochToDate(data.updated_at || undefined);
140144
}
@@ -153,6 +157,7 @@ export class Client extends BaseResource implements ClientResource {
153157
captcha_bypass: this.captchaBypass,
154158
cookie_expires_at: this.cookieExpiresAt ? this.cookieExpiresAt.getTime() : null,
155159
last_authentication_strategy: this.lastAuthenticationStrategy ?? null,
160+
...(this.clientTrustState && { client_trust_state: this.clientTrustState }),
156161
created_at: this.createdAt?.getTime() ?? null,
157162
updated_at: this.updatedAt?.getTime() ?? null,
158163
};

packages/shared/src/types/client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { LastAuthenticationStrategy } from './json';
1+
import type { ClientTrustState, LastAuthenticationStrategy } from './json';
22
import type { ClerkResource } from './resource';
33
import type { ActiveSessionResource, SessionResource, SignedInSessionResource } from './session';
44
import type { SignInResource } from './signIn';
@@ -20,6 +20,7 @@ export interface ClientResource extends ClerkResource {
2020
lastActiveSessionId: string | null;
2121
/** Last authentication strategy used by this client; `null` when unknown or feature disabled. */
2222
lastAuthenticationStrategy: LastAuthenticationStrategy | null;
23+
clientTrustState?: ClientTrustState;
2324
captchaBypass: boolean;
2425
cookieExpiresAt: Date | null;
2526
createdAt: Date | null;

packages/shared/src/types/json.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ export type LastAuthenticationStrategy =
102102
| OAuthStrategy
103103
| Web3Strategy;
104104

105+
export type ClientTrustState = 'new' | 'known' | 'pending';
106+
105107
export interface ClientJSON extends ClerkResourceJSON {
106108
object: 'client';
107109
id: string;
@@ -111,6 +113,7 @@ export interface ClientJSON extends ClerkResourceJSON {
111113
captcha_bypass?: boolean; // this is used by the @clerk/testing package
112114
last_active_session_id: string | null;
113115
last_authentication_strategy: LastAuthenticationStrategy | null;
116+
client_trust_state?: ClientTrustState;
114117
cookie_expires_at: number | null;
115118
created_at: number;
116119
updated_at: number;

0 commit comments

Comments
 (0)