Skip to content

Commit a474c59

Browse files
authored
fix(clerk-js,shared): Move clientTrustState to SignIn (#7163)
1 parent b505755 commit a474c59

File tree

8 files changed

+17
-10
lines changed

8 files changed

+17
-10
lines changed

.changeset/evil-aliens-hope.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/shared': patch
4+
---
5+
6+
Move clientTrustState to SignIn

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
ClientJSON,
44
ClientJSONSnapshot,
55
ClientResource,
6-
ClientTrustState,
76
LastAuthenticationStrategy,
87
SignedInSessionResource,
98
SignInResource,
@@ -27,7 +26,6 @@ export class Client extends BaseResource implements ClientResource {
2726
cookieExpiresAt: Date | null = null;
2827
/** Last authentication strategy used by this client; `null` when unknown/disabled. */
2928
lastAuthenticationStrategy: LastAuthenticationStrategy | null = null;
30-
clientTrustState?: ClientTrustState = undefined;
3129
createdAt: Date | null = null;
3230
updatedAt: Date | null = null;
3331

@@ -88,7 +86,6 @@ export class Client extends BaseResource implements ClientResource {
8886
this.signIn = new SignIn(null);
8987
this.lastActiveSessionId = null;
9088
this.lastAuthenticationStrategy = null;
91-
this.clientTrustState = undefined;
9289
this.cookieExpiresAt = null;
9390
this.createdAt = null;
9491
this.updatedAt = null;
@@ -138,7 +135,6 @@ export class Client extends BaseResource implements ClientResource {
138135
this.captchaBypass = data.captcha_bypass || false;
139136
this.cookieExpiresAt = data.cookie_expires_at ? unixEpochToDate(data.cookie_expires_at) : null;
140137
this.lastAuthenticationStrategy = data.last_authentication_strategy || null;
141-
this.clientTrustState = data.client_trust_state;
142138
this.createdAt = unixEpochToDate(data.created_at || undefined);
143139
this.updatedAt = unixEpochToDate(data.updated_at || undefined);
144140
}
@@ -157,7 +153,6 @@ export class Client extends BaseResource implements ClientResource {
157153
captcha_bypass: this.captchaBypass,
158154
cookie_expires_at: this.cookieExpiresAt ? this.cookieExpiresAt.getTime() : null,
159155
last_authentication_strategy: this.lastAuthenticationStrategy ?? null,
160-
...(this.clientTrustState && { client_trust_state: this.clientTrustState }),
161156
created_at: this.createdAt?.getTime() ?? null,
162157
updated_at: this.updatedAt?.getTime() ?? null,
163158
};

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
AuthenticateWithPopupParams,
99
AuthenticateWithRedirectParams,
1010
AuthenticateWithWeb3Params,
11+
ClientTrustState,
1112
CreateEmailLinkFlowReturn,
1213
EmailCodeConfig,
1314
EmailCodeFactor,
@@ -109,6 +110,7 @@ export class SignIn extends BaseResource implements SignInResource {
109110
identifier: string | null = null;
110111
createdSessionId: string | null = null;
111112
userData: UserData = new UserData(null);
113+
clientTrustState?: ClientTrustState;
112114

113115
/**
114116
* The current status of the sign-in process.
@@ -532,6 +534,7 @@ export class SignIn extends BaseResource implements SignInResource {
532534
this.secondFactorVerification = new Verification(data.second_factor_verification);
533535
this.createdSessionId = data.created_session_id;
534536
this.userData = new UserData(data.user_data);
537+
this.clientTrustState = data.client_trust_state ?? undefined;
535538
}
536539

537540
eventBus.emit('resource:update', { resource: this });

packages/shared/src/types/client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ClientTrustState, LastAuthenticationStrategy } from './json';
1+
import type { LastAuthenticationStrategy } from './json';
22
import type { ClerkResource } from './resource';
33
import type { ActiveSessionResource, SessionResource, SignedInSessionResource } from './session';
44
import type { SignInResource } from './signIn';
@@ -20,7 +20,6 @@ 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;
2423
captchaBypass: boolean;
2524
cookieExpiresAt: Date | null;
2625
createdAt: Date | null;

packages/shared/src/types/json.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ export interface ClientJSON extends ClerkResourceJSON {
113113
captcha_bypass?: boolean; // this is used by the @clerk/testing package
114114
last_active_session_id: string | null;
115115
last_authentication_strategy: LastAuthenticationStrategy | null;
116-
client_trust_state?: ClientTrustState;
117116
cookie_expires_at: number | null;
118117
created_at: number;
119118
updated_at: number;

packages/shared/src/types/signIn.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {
22
ClerkResourceJSON,
3+
ClientTrustState,
34
SignInFirstFactorJSON,
45
SignInSecondFactorJSON,
56
UserDataJSON,
@@ -42,6 +43,7 @@ export interface SignInResource extends ClerkResource {
4243
supportedIdentifiers: SignInIdentifier[];
4344
supportedFirstFactors: SignInFirstFactor[] | null;
4445
supportedSecondFactors: SignInSecondFactor[] | null;
46+
clientTrustState?: ClientTrustState;
4547
firstFactorVerification: VerificationResource;
4648
secondFactorVerification: VerificationResource;
4749
identifier: string | null;
@@ -94,6 +96,7 @@ export interface SignInJSON extends ClerkResourceJSON {
9496
object: 'sign_in';
9597
id: string;
9698
status: SignInStatus;
99+
client_trust_state?: ClientTrustState;
97100
/**
98101
* @deprecated This attribute will be removed in the next major version.
99102
*/

packages/shared/src/types/signInCommon.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export type SignInFirstFactor =
8585
| SamlFactor
8686
| EnterpriseSSOFactor;
8787

88-
export type SignInSecondFactor = PhoneCodeFactor | TOTPFactor | BackupCodeFactor;
88+
export type SignInSecondFactor = PhoneCodeFactor | TOTPFactor | BackupCodeFactor | EmailCodeFactor;
8989

9090
export interface UserData {
9191
firstName?: string;
@@ -119,7 +119,7 @@ export type AttemptFirstFactorParams =
119119

120120
export type PrepareSecondFactorParams = PhoneCodeSecondFactorConfig;
121121

122-
export type AttemptSecondFactorParams = PhoneCodeAttempt | TOTPAttempt | BackupCodeAttempt;
122+
export type AttemptSecondFactorParams = PhoneCodeAttempt | TOTPAttempt | BackupCodeAttempt | EmailCodeAttempt;
123123

124124
export type SignInCreateParams = (
125125
| {

packages/shared/src/types/snapshots.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { DisplayConfigJSON } from './displayConfig';
66
import type {
77
AuthConfigJSON,
88
ClientJSON,
9+
ClientTrustState,
910
EmailAddressJSON,
1011
EnterpriseAccountConnectionJSON,
1112
EnterpriseAccountJSON,
@@ -40,6 +41,7 @@ export type SignInJSONSnapshot = Override<
4041
first_factor_verification: VerificationJSONSnapshot;
4142
second_factor_verification: VerificationJSONSnapshot;
4243
user_data: UserDataJSONSnapshot;
44+
client_trust_state?: ClientTrustState;
4345
}
4446
>;
4547

0 commit comments

Comments
 (0)