Skip to content

Commit 3989a2d

Browse files
chriscanintmilewski
authored andcommitted
feat(clerk-js, types): Add clientTrustState and untrustedFirstFactors to Client and SignIn resources
- Trusted users automatically see password - Untrusted users automatically don't see password - Added Expo dummy data.
1 parent 02b723d commit 3989a2d

File tree

8 files changed

+22
-2
lines changed

8 files changed

+22
-2
lines changed

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 | null = null;
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 = null;
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 || null;
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+
client_trust_state: this.clientTrustState ?? null,
156161
created_at: this.createdAt?.getTime() ?? null,
157162
updated_at: this.updatedAt?.getTime() ?? null,
158163
};

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export class SignIn extends BaseResource implements SignInResource {
103103
private _status: SignInStatus | null = null;
104104
supportedIdentifiers: SignInIdentifier[] = [];
105105
supportedFirstFactors: SignInFirstFactor[] | null = [];
106+
untrustedFirstFactors: SignInFirstFactor[] | null = [];
106107
supportedSecondFactors: SignInSecondFactor[] | null = null;
107108
firstFactorVerification: VerificationResource = new Verification(null);
108109
secondFactorVerification: VerificationResource = new Verification(null);
@@ -527,6 +528,7 @@ export class SignIn extends BaseResource implements SignInResource {
527528
this.supportedIdentifiers = data.supported_identifiers;
528529
this.identifier = data.identifier;
529530
this.supportedFirstFactors = deepSnakeToCamel(data.supported_first_factors) as SignInFirstFactor[] | null;
531+
this.untrustedFirstFactors = deepSnakeToCamel(data.untrusted_first_factors) as SignInFirstFactor[] | null;
530532
this.supportedSecondFactors = deepSnakeToCamel(data.supported_second_factors) as SignInSecondFactor[] | null;
531533
this.firstFactorVerification = new Verification(data.first_factor_verification);
532534
this.secondFactorVerification = new Verification(data.second_factor_verification);
@@ -545,6 +547,7 @@ export class SignIn extends BaseResource implements SignInResource {
545547
status: this.status || null,
546548
supported_identifiers: this.supportedIdentifiers,
547549
supported_first_factors: deepCamelToSnake(this.supportedFirstFactors),
550+
untrusted_first_factors: deepCamelToSnake(this.untrustedFirstFactors),
548551
supported_second_factors: deepCamelToSnake(this.supportedSecondFactors),
549552
first_factor_verification: this.firstFactorVerification.__internal_toSnapshot(),
550553
second_factor_verification: this.secondFactorVerification.__internal_toSnapshot(),

packages/clerk-js/src/test/core-fixtures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export const createSignIn = (signInParams: Partial<SignInJSON> = {}, user: Parti
208208
object: 'sign_in',
209209
second_factor_verification: signInParams.second_factor_verification,
210210
supported_first_factors: signInParams.supported_first_factors,
211+
untrusted_first_factors: signInParams.untrusted_first_factors || [],
211212
supported_second_factors: signInParams.supported_second_factors,
212213
user_data: {
213214
first_name: user.first_name,

packages/expo/src/cache/dummy-data/client-resource.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export const DUMMY_CLERK_CLIENT_RESOURCE = {
9292
status: null,
9393
supported_identifiers: [],
9494
supported_first_factors: [],
95+
untrusted_first_factors: [],
9596
supported_second_factors: null,
9697
first_factor_verification: {
9798
object: 'verification',
@@ -126,6 +127,7 @@ export const DUMMY_CLERK_CLIENT_RESOURCE = {
126127
last_active_session_id: null,
127128
cookie_expires_at: null,
128129
last_authentication_strategy: null,
130+
client_trust_state: null,
129131
created_at: new Date().getTime(),
130132
updated_at: new Date().getTime(),
131133
} as unknown as ClientJSONSnapshot;

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 | null;
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 | null;
114117
cookie_expires_at: number | null;
115118
created_at: number;
116119
updated_at: number;

packages/shared/src/types/signIn.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface SignInResource extends ClerkResource {
4141
*/
4242
supportedIdentifiers: SignInIdentifier[];
4343
supportedFirstFactors: SignInFirstFactor[] | null;
44+
untrustedFirstFactors: SignInFirstFactor[] | null;
4445
supportedSecondFactors: SignInSecondFactor[] | null;
4546
firstFactorVerification: VerificationResource;
4647
secondFactorVerification: VerificationResource;
@@ -101,6 +102,7 @@ export interface SignInJSON extends ClerkResourceJSON {
101102
identifier: string;
102103
user_data: UserDataJSON;
103104
supported_first_factors: SignInFirstFactorJSON[];
105+
untrusted_first_factors: SignInFirstFactorJSON[];
104106
supported_second_factors: SignInSecondFactorJSON[];
105107
first_factor_verification: VerificationJSON | null;
106108
second_factor_verification: VerificationJSON | null;

packages/shared/src/types/snapshots.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ import type { UserSettingsJSON } from './userSettings';
3535
import type { Nullable, Override } from './utils';
3636

3737
export type SignInJSONSnapshot = Override<
38-
Nullable<SignInJSON, 'status' | 'identifier' | 'supported_first_factors' | 'supported_second_factors'>,
38+
Nullable<
39+
SignInJSON,
40+
'status' | 'identifier' | 'supported_first_factors' | 'untrusted_first_factors' | 'supported_second_factors'
41+
>,
3942
{
4043
first_factor_verification: VerificationJSONSnapshot;
4144
second_factor_verification: VerificationJSONSnapshot;

0 commit comments

Comments
 (0)