Skip to content

Commit 6f2cafa

Browse files
authored
refactor(types,clerk-js): Extract SignInFuture and SignUpFuture method params into types (#6645)
1 parent 30c8bca commit 6f2cafa

12 files changed

Lines changed: 532 additions & 441 deletions

File tree

.changeset/lovely-bananas-allow.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

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

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type {
1616
EmailCodeConfig,
1717
EmailLinkConfig,
1818
EnterpriseSSOConfig,
19-
OAuthStrategy,
2019
PassKeyConfig,
2120
PasskeyFactor,
2221
PhoneCodeConfig,
@@ -26,10 +25,16 @@ import type {
2625
ResetPasswordParams,
2726
ResetPasswordPhoneCodeFactorConfig,
2827
SamlConfig,
29-
SetActiveNavigate,
3028
SignInCreateParams,
3129
SignInFirstFactor,
30+
SignInFutureCreateParams,
31+
SignInFutureEmailCodeSendParams,
32+
SignInFutureEmailCodeVerifyParams,
33+
SignInFutureFinalizeParams,
34+
SignInFuturePasswordParams,
35+
SignInFutureResetPasswordSubmitParams,
3236
SignInFutureResource,
37+
SignInFutureSSOParams,
3338
SignInIdentifier,
3439
SignInJSON,
3540
SignInJSONSnapshot,
@@ -551,7 +556,8 @@ class SignInFuture implements SignInFutureResource {
551556
});
552557
}
553558

554-
async verifyResetPasswordEmailCode({ code }: { code: string }): Promise<{ error: unknown }> {
559+
async verifyResetPasswordEmailCode(params: SignInFutureEmailCodeVerifyParams): Promise<{ error: unknown }> {
560+
const { code } = params;
555561
return runAsyncResourceTask(this.resource, async () => {
556562
await this.resource.__internal_basePost({
557563
body: { code, strategy: 'reset_password_email_code' },
@@ -560,13 +566,8 @@ class SignInFuture implements SignInFutureResource {
560566
});
561567
}
562568

563-
async submitResetPassword({
564-
password,
565-
signOutOfOtherSessions = true,
566-
}: {
567-
password: string;
568-
signOutOfOtherSessions?: boolean;
569-
}): Promise<{ error: unknown }> {
569+
async submitResetPassword(params: SignInFutureResetPasswordSubmitParams): Promise<{ error: unknown }> {
570+
const { password, signOutOfOtherSessions = true } = params;
570571
return runAsyncResourceTask(this.resource, async () => {
571572
await this.resource.__internal_basePost({
572573
body: { password, signOutOfOtherSessions },
@@ -575,13 +576,7 @@ class SignInFuture implements SignInFutureResource {
575576
});
576577
}
577578

578-
async create(params: {
579-
identifier?: string;
580-
strategy?: OAuthStrategy | 'saml' | 'enterprise_sso';
581-
redirectUrl?: string;
582-
actionCompleteRedirectUrl?: string;
583-
transfer?: boolean;
584-
}): Promise<{ error: unknown }> {
579+
async create(params: SignInFutureCreateParams): Promise<{ error: unknown }> {
585580
return runAsyncResourceTask(this.resource, async () => {
586581
await this.resource.__internal_basePost({
587582
path: this.resource.pathRoot,
@@ -590,7 +585,8 @@ class SignInFuture implements SignInFutureResource {
590585
});
591586
}
592587

593-
async password({ identifier, password }: { identifier?: string; password: string }): Promise<{ error: unknown }> {
588+
async password(params: SignInFuturePasswordParams): Promise<{ error: unknown }> {
589+
const { identifier, password } = params;
594590
return runAsyncResourceTask(this.resource, async () => {
595591
const previousIdentifier = this.resource.identifier;
596592
await this.resource.__internal_basePost({
@@ -600,7 +596,8 @@ class SignInFuture implements SignInFutureResource {
600596
});
601597
}
602598

603-
async sendEmailCode({ email }: { email: string }): Promise<{ error: unknown }> {
599+
async sendEmailCode(params: SignInFutureEmailCodeSendParams): Promise<{ error: unknown }> {
600+
const { email } = params;
604601
return runAsyncResourceTask(this.resource, async () => {
605602
if (!this.resource.id) {
606603
await this.create({ identifier: email });
@@ -620,7 +617,8 @@ class SignInFuture implements SignInFutureResource {
620617
});
621618
}
622619

623-
async verifyEmailCode({ code }: { code: string }): Promise<{ error: unknown }> {
620+
async verifyEmailCode(params: SignInFutureEmailCodeVerifyParams): Promise<{ error: unknown }> {
621+
const { code } = params;
624622
return runAsyncResourceTask(this.resource, async () => {
625623
await this.resource.__internal_basePost({
626624
body: { code, strategy: 'email_code' },
@@ -629,29 +627,18 @@ class SignInFuture implements SignInFutureResource {
629627
});
630628
}
631629

632-
async sso({
633-
flow = 'auto',
634-
strategy,
635-
redirectUrl,
636-
redirectUrlComplete,
637-
}: {
638-
flow?: 'auto' | 'modal';
639-
strategy: OAuthStrategy | 'saml' | 'enterprise_sso';
640-
redirectUrl: string;
641-
redirectUrlComplete: string;
642-
}): Promise<{ error: unknown }> {
630+
async sso(params: SignInFutureSSOParams): Promise<{ error: unknown }> {
631+
const { flow = 'auto', strategy, redirectUrl, redirectCallbackUrl } = params;
643632
return runAsyncResourceTask(this.resource, async () => {
644633
if (flow !== 'auto') {
645634
throw new Error('modal flow is not supported yet');
646635
}
647636

648-
const redirectUrlWithAuthToken = SignIn.clerk.buildUrlWithAuth(redirectUrl);
649-
650637
if (!this.resource.id) {
651638
await this.create({
652639
strategy,
653-
redirectUrl: redirectUrlWithAuthToken,
654-
actionCompleteRedirectUrl: redirectUrlComplete,
640+
redirectUrl: SignIn.clerk.buildUrlWithAuth(redirectCallbackUrl),
641+
actionCompleteRedirectUrl: redirectUrl,
655642
});
656643
}
657644

@@ -663,7 +650,8 @@ class SignInFuture implements SignInFutureResource {
663650
});
664651
}
665652

666-
async finalize({ navigate }: { navigate?: SetActiveNavigate } = {}): Promise<{ error: unknown }> {
653+
async finalize(params?: SignInFutureFinalizeParams): Promise<{ error: unknown }> {
654+
const { navigate } = params || {};
667655
return runAsyncResourceTask(this.resource, async () => {
668656
if (!this.resource.createdSessionId) {
669657
throw new Error('Cannot finalize sign-in without a created session.');

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ import type {
1414
PreparePhoneNumberVerificationParams,
1515
PrepareVerificationParams,
1616
PrepareWeb3WalletVerificationParams,
17-
SetActiveNavigate,
1817
SignUpAuthenticateWithWeb3Params,
1918
SignUpCreateParams,
2019
SignUpField,
20+
SignUpFutureCreateParams,
21+
SignUpFutureEmailCodeVerifyParams,
22+
SignUpFutureFinalizeParams,
23+
SignUpFuturePasswordParams,
2124
SignUpFutureResource,
25+
SignUpFutureSSoParams,
2226
SignUpIdentificationField,
2327
SignUpJSON,
2428
SignUpJSONSnapshot,
@@ -541,7 +545,8 @@ class SignUpFuture implements SignUpFutureResource {
541545
return { captchaToken, captchaWidgetType, captchaError };
542546
}
543547

544-
async create({ transfer }: { transfer?: boolean }): Promise<{ error: unknown }> {
548+
async create(params: SignUpFutureCreateParams): Promise<{ error: unknown }> {
549+
const { transfer } = params;
545550
return runAsyncResourceTask(this.resource, async () => {
546551
const { captchaToken, captchaWidgetType, captchaError } = await this.getCaptchaToken();
547552
await this.resource.__internal_basePost({
@@ -551,7 +556,8 @@ class SignUpFuture implements SignUpFutureResource {
551556
});
552557
}
553558

554-
async password({ emailAddress, password }: { emailAddress: string; password: string }): Promise<{ error: unknown }> {
559+
async password(params: SignUpFuturePasswordParams): Promise<{ error: unknown }> {
560+
const { emailAddress, password } = params;
555561
return runAsyncResourceTask(this.resource, async () => {
556562
const { captchaToken, captchaWidgetType, captchaError } = await this.getCaptchaToken();
557563

@@ -578,7 +584,8 @@ class SignUpFuture implements SignUpFutureResource {
578584
});
579585
}
580586

581-
async verifyEmailCode({ code }: { code: string }): Promise<{ error: unknown }> {
587+
async verifyEmailCode(params: SignUpFutureEmailCodeVerifyParams): Promise<{ error: unknown }> {
588+
const { code } = params;
582589
return runAsyncResourceTask(this.resource, async () => {
583590
await this.resource.__internal_basePost({
584591
body: { strategy: 'email_code', code },
@@ -587,23 +594,16 @@ class SignUpFuture implements SignUpFutureResource {
587594
});
588595
}
589596

590-
async sso({
591-
strategy,
592-
redirectUrl,
593-
redirectUrlComplete,
594-
}: {
595-
strategy: string;
596-
redirectUrl: string;
597-
redirectUrlComplete: string;
598-
}): Promise<{ error: unknown }> {
597+
async sso(params: SignUpFutureSSoParams): Promise<{ error: unknown }> {
598+
const { strategy, redirectUrl, redirectCallbackUrl } = params;
599599
return runAsyncResourceTask(this.resource, async () => {
600600
const { captchaToken, captchaWidgetType, captchaError } = await this.getCaptchaToken();
601601
await this.resource.__internal_basePost({
602602
path: this.resource.pathRoot,
603603
body: {
604604
strategy,
605-
redirectUrl: SignUp.clerk.buildUrlWithAuth(redirectUrl),
606-
redirectUrlComplete,
605+
redirectUrl: SignUp.clerk.buildUrlWithAuth(redirectCallbackUrl),
606+
redirectUrlComplete: redirectUrl,
607607
captchaToken,
608608
captchaWidgetType,
609609
captchaError,
@@ -620,7 +620,8 @@ class SignUpFuture implements SignUpFutureResource {
620620
});
621621
}
622622

623-
async finalize({ navigate }: { navigate?: SetActiveNavigate } = {}): Promise<{ error: unknown }> {
623+
async finalize(params?: SignUpFutureFinalizeParams): Promise<{ error: unknown }> {
624+
const { navigate } = params || {};
624625
return runAsyncResourceTask(this.resource, async () => {
625626
if (!this.resource.createdSessionId) {
626627
throw new Error('Cannot finalize sign-up without a created session.');

packages/types/src/index.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
export * from './api';
2+
export * from './apiKeys';
3+
export * from './apiKeysSettings';
24
export * from './appearance';
3-
export * from './elementIds';
45
export * from './attributes';
56
export * from './authConfig';
7+
export * from './authObject';
68
export * from './backupCode';
79
export * from './clerk';
810
export * from './client';
911
export * from './commerce';
1012
export * from './commerceSettings';
13+
export * from './customMenuItems';
14+
export * from './customPages';
1115
export * from './deletedObject';
1216
export * from './displayConfig';
17+
export * from './elementIds';
1318
export * from './emailAddress';
19+
export * from './enterpriseAccount';
1420
export * from './environment';
1521
export * from './externalAccount';
16-
export * from './enterpriseAccount';
1722
export * from './factors';
1823
export * from './hooks';
1924
export * from './identificationLink';
@@ -22,9 +27,9 @@ export * from './image';
2227
export * from './instance';
2328
export * from './json';
2429
export * from './jwt';
30+
export * from './jwtv2';
2531
export * from './key';
2632
export * from './localization';
27-
export * from './jwtv2';
2833
export * from './multiDomain';
2934
export * from './oauth';
3035
export * from './organization';
@@ -34,8 +39,11 @@ export * from './organizationMembership';
3439
export * from './organizationMembershipRequest';
3540
export * from './organizationSettings';
3641
export * from './organizationSuggestion';
42+
export * from './pagination';
43+
export * from './passkey';
3744
export * from './passwords';
3845
export * from './permission';
46+
export * from './phoneCodeChannel';
3947
export * from './phoneNumber';
4048
export * from './protect';
4149
export * from './redirects';
@@ -44,32 +52,28 @@ export * from './role';
4452
export * from './router';
4553
export * from './saml';
4654
export * from './samlAccount';
55+
export * from './samlConnection';
4756
export * from './session';
4857
export * from './sessionVerification';
4958
export * from './signIn';
59+
export * from './signInCommon';
60+
export * from './signInFuture';
5061
export * from './signUp';
62+
export * from './signUpCommon';
63+
export * from './signUpFuture';
64+
export * from './snapshots';
5165
export * from './ssr';
5266
export * from './state';
5367
export * from './strategies';
68+
export * from './telemetry';
5469
export * from './theme';
5570
export * from './token';
5671
export * from './totp';
57-
export * from './telemetry';
5872
export * from './user';
5973
export * from './userOrganizationInvitation';
6074
export * from './userSettings';
6175
export * from './utils';
6276
export * from './verification';
77+
export * from './waitlist';
6378
export * from './web3';
6479
export * from './web3Wallet';
65-
export * from './customPages';
66-
export * from './pagination';
67-
export * from './passkey';
68-
export * from './customMenuItems';
69-
export * from './samlConnection';
70-
export * from './waitlist';
71-
export * from './apiKeys';
72-
export * from './apiKeysSettings';
73-
export * from './snapshots';
74-
export * from './authObject';
75-
export * from './phoneCodeChannel';

packages/types/src/json.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ import type { PhoneCodeChannel } from './phoneCodeChannel';
2626
import type { SamlIdpSlug } from './saml';
2727
import type { SessionStatus, SessionTask } from './session';
2828
import type { SessionVerificationLevel, SessionVerificationStatus } from './sessionVerification';
29-
import type { SignInFirstFactor, SignInJSON, SignInSecondFactor } from './signIn';
30-
import type { SignUpField, SignUpIdentificationField, SignUpStatus } from './signUp';
29+
import type { SignInJSON } from './signIn';
30+
import type { SignInFirstFactor, SignInSecondFactor } from './signInCommon';
31+
import type { SignUpField, SignUpIdentificationField, SignUpStatus } from './signUpCommon';
3132
import type { BoxShadow, Color, EmUnit, FontWeight, HexColor } from './theme';
3233
import type { UserSettingsJSON } from './userSettings';
3334
import type { CamelToSnake } from './utils';

0 commit comments

Comments
 (0)