diff --git a/.changeset/evil-aliens-hope.md b/.changeset/evil-aliens-hope.md new file mode 100644 index 00000000000..059f451f562 --- /dev/null +++ b/.changeset/evil-aliens-hope.md @@ -0,0 +1,6 @@ +--- +'@clerk/clerk-js': patch +'@clerk/shared': patch +--- + +Move clientTrustState to SignIn diff --git a/packages/clerk-js/src/core/resources/Client.ts b/packages/clerk-js/src/core/resources/Client.ts index f8a727d8845..3371b8435c0 100644 --- a/packages/clerk-js/src/core/resources/Client.ts +++ b/packages/clerk-js/src/core/resources/Client.ts @@ -3,7 +3,6 @@ import type { ClientJSON, ClientJSONSnapshot, ClientResource, - ClientTrustState, LastAuthenticationStrategy, SignedInSessionResource, SignInResource, @@ -27,7 +26,6 @@ export class Client extends BaseResource implements ClientResource { cookieExpiresAt: Date | null = null; /** Last authentication strategy used by this client; `null` when unknown/disabled. */ lastAuthenticationStrategy: LastAuthenticationStrategy | null = null; - clientTrustState?: ClientTrustState = undefined; createdAt: Date | null = null; updatedAt: Date | null = null; @@ -88,7 +86,6 @@ export class Client extends BaseResource implements ClientResource { this.signIn = new SignIn(null); this.lastActiveSessionId = null; this.lastAuthenticationStrategy = null; - this.clientTrustState = undefined; this.cookieExpiresAt = null; this.createdAt = null; this.updatedAt = null; @@ -138,7 +135,6 @@ export class Client extends BaseResource implements ClientResource { this.captchaBypass = data.captcha_bypass || false; this.cookieExpiresAt = data.cookie_expires_at ? unixEpochToDate(data.cookie_expires_at) : null; this.lastAuthenticationStrategy = data.last_authentication_strategy || null; - this.clientTrustState = data.client_trust_state; this.createdAt = unixEpochToDate(data.created_at || undefined); this.updatedAt = unixEpochToDate(data.updated_at || undefined); } @@ -157,7 +153,6 @@ export class Client extends BaseResource implements ClientResource { captcha_bypass: this.captchaBypass, cookie_expires_at: this.cookieExpiresAt ? this.cookieExpiresAt.getTime() : null, last_authentication_strategy: this.lastAuthenticationStrategy ?? null, - ...(this.clientTrustState && { client_trust_state: this.clientTrustState }), created_at: this.createdAt?.getTime() ?? null, updated_at: this.updatedAt?.getTime() ?? null, }; diff --git a/packages/clerk-js/src/core/resources/SignIn.ts b/packages/clerk-js/src/core/resources/SignIn.ts index 5f9e53b58c2..d7b47404b37 100644 --- a/packages/clerk-js/src/core/resources/SignIn.ts +++ b/packages/clerk-js/src/core/resources/SignIn.ts @@ -8,6 +8,7 @@ import type { AuthenticateWithPopupParams, AuthenticateWithRedirectParams, AuthenticateWithWeb3Params, + ClientTrustState, CreateEmailLinkFlowReturn, EmailCodeConfig, EmailCodeFactor, @@ -109,6 +110,7 @@ export class SignIn extends BaseResource implements SignInResource { identifier: string | null = null; createdSessionId: string | null = null; userData: UserData = new UserData(null); + clientTrustState?: ClientTrustState; /** * The current status of the sign-in process. @@ -532,6 +534,7 @@ export class SignIn extends BaseResource implements SignInResource { this.secondFactorVerification = new Verification(data.second_factor_verification); this.createdSessionId = data.created_session_id; this.userData = new UserData(data.user_data); + this.clientTrustState = data.client_trust_state ?? undefined; } eventBus.emit('resource:update', { resource: this }); diff --git a/packages/shared/src/types/client.ts b/packages/shared/src/types/client.ts index ffc8e8db754..1a8585cfc39 100644 --- a/packages/shared/src/types/client.ts +++ b/packages/shared/src/types/client.ts @@ -1,4 +1,4 @@ -import type { ClientTrustState, LastAuthenticationStrategy } from './json'; +import type { LastAuthenticationStrategy } from './json'; import type { ClerkResource } from './resource'; import type { ActiveSessionResource, SessionResource, SignedInSessionResource } from './session'; import type { SignInResource } from './signIn'; @@ -20,7 +20,6 @@ export interface ClientResource extends ClerkResource { lastActiveSessionId: string | null; /** Last authentication strategy used by this client; `null` when unknown or feature disabled. */ lastAuthenticationStrategy: LastAuthenticationStrategy | null; - clientTrustState?: ClientTrustState; captchaBypass: boolean; cookieExpiresAt: Date | null; createdAt: Date | null; diff --git a/packages/shared/src/types/json.ts b/packages/shared/src/types/json.ts index 516c198c183..958bf695941 100644 --- a/packages/shared/src/types/json.ts +++ b/packages/shared/src/types/json.ts @@ -113,7 +113,6 @@ export interface ClientJSON extends ClerkResourceJSON { captcha_bypass?: boolean; // this is used by the @clerk/testing package last_active_session_id: string | null; last_authentication_strategy: LastAuthenticationStrategy | null; - client_trust_state?: ClientTrustState; cookie_expires_at: number | null; created_at: number; updated_at: number; diff --git a/packages/shared/src/types/signIn.ts b/packages/shared/src/types/signIn.ts index 6ffa69aa1fd..e37018e15c3 100644 --- a/packages/shared/src/types/signIn.ts +++ b/packages/shared/src/types/signIn.ts @@ -1,5 +1,6 @@ import type { ClerkResourceJSON, + ClientTrustState, SignInFirstFactorJSON, SignInSecondFactorJSON, UserDataJSON, @@ -42,6 +43,7 @@ export interface SignInResource extends ClerkResource { supportedIdentifiers: SignInIdentifier[]; supportedFirstFactors: SignInFirstFactor[] | null; supportedSecondFactors: SignInSecondFactor[] | null; + clientTrustState?: ClientTrustState; firstFactorVerification: VerificationResource; secondFactorVerification: VerificationResource; identifier: string | null; @@ -94,6 +96,7 @@ export interface SignInJSON extends ClerkResourceJSON { object: 'sign_in'; id: string; status: SignInStatus; + client_trust_state?: ClientTrustState; /** * @deprecated This attribute will be removed in the next major version. */ diff --git a/packages/shared/src/types/signInCommon.ts b/packages/shared/src/types/signInCommon.ts index 30cacb7e517..a7b07f280ff 100644 --- a/packages/shared/src/types/signInCommon.ts +++ b/packages/shared/src/types/signInCommon.ts @@ -85,7 +85,7 @@ export type SignInFirstFactor = | SamlFactor | EnterpriseSSOFactor; -export type SignInSecondFactor = PhoneCodeFactor | TOTPFactor | BackupCodeFactor; +export type SignInSecondFactor = PhoneCodeFactor | TOTPFactor | BackupCodeFactor | EmailCodeFactor; export interface UserData { firstName?: string; @@ -119,7 +119,7 @@ export type AttemptFirstFactorParams = export type PrepareSecondFactorParams = PhoneCodeSecondFactorConfig; -export type AttemptSecondFactorParams = PhoneCodeAttempt | TOTPAttempt | BackupCodeAttempt; +export type AttemptSecondFactorParams = PhoneCodeAttempt | TOTPAttempt | BackupCodeAttempt | EmailCodeAttempt; export type SignInCreateParams = ( | { diff --git a/packages/shared/src/types/snapshots.ts b/packages/shared/src/types/snapshots.ts index 13c423e8cb3..36524a5cf28 100644 --- a/packages/shared/src/types/snapshots.ts +++ b/packages/shared/src/types/snapshots.ts @@ -6,6 +6,7 @@ import type { DisplayConfigJSON } from './displayConfig'; import type { AuthConfigJSON, ClientJSON, + ClientTrustState, EmailAddressJSON, EnterpriseAccountConnectionJSON, EnterpriseAccountJSON, @@ -40,6 +41,7 @@ export type SignInJSONSnapshot = Override< first_factor_verification: VerificationJSONSnapshot; second_factor_verification: VerificationJSONSnapshot; user_data: UserDataJSONSnapshot; + client_trust_state?: ClientTrustState; } >;