diff --git a/.changeset/giant-cats-lay.md b/.changeset/giant-cats-lay.md new file mode 100644 index 00000000000..4164c160b3d --- /dev/null +++ b/.changeset/giant-cats-lay.md @@ -0,0 +1,6 @@ +--- +'@clerk/clerk-js': minor +'@clerk/types': minor +--- + +[Experimental] Fix `signIn.password` emailAddress parameter name. diff --git a/.changeset/purple-toys-refuse.md b/.changeset/purple-toys-refuse.md new file mode 100644 index 00000000000..9aa9afd7450 --- /dev/null +++ b/.changeset/purple-toys-refuse.md @@ -0,0 +1,6 @@ +--- +'@clerk/clerk-js': minor +'@clerk/types': minor +--- + +[Experimental] Fix issue where calling `this.create()` would not correctly propagate errors. diff --git a/packages/clerk-js/src/core/resources/SignIn.ts b/packages/clerk-js/src/core/resources/SignIn.ts index 4c5279a00ce..e72b9490851 100644 --- a/packages/clerk-js/src/core/resources/SignIn.ts +++ b/packages/clerk-js/src/core/resources/SignIn.ts @@ -703,23 +703,27 @@ class SignInFuture implements SignInFutureResource { }); } + private async _create(params: SignInFutureCreateParams): Promise { + await this.resource.__internal_basePost({ + path: this.resource.pathRoot, + body: params, + }); + } + async create(params: SignInFutureCreateParams): Promise<{ error: unknown }> { return runAsyncResourceTask(this.resource, async () => { - await this.resource.__internal_basePost({ - path: this.resource.pathRoot, - body: params, - }); + await this._create(params); }); } async password(params: SignInFuturePasswordParams): Promise<{ error: unknown }> { - if ([params.identifier, params.email, params.phoneNumber].filter(Boolean).length > 1) { - throw new Error('Only one of identifier, email, or phoneNumber can be provided'); + if ([params.identifier, params.emailAddress, params.phoneNumber].filter(Boolean).length > 1) { + throw new Error('Only one of identifier, emailAddress, or phoneNumber can be provided'); } return runAsyncResourceTask(this.resource, async () => { // TODO @userland-errors: - const identifier = params.identifier || params.email || params.phoneNumber; + const identifier = params.identifier || params.emailAddress || params.phoneNumber; const previousIdentifier = this.resource.identifier; await this.resource.__internal_basePost({ path: this.resource.pathRoot, @@ -744,7 +748,7 @@ class SignInFuture implements SignInFutureResource { return runAsyncResourceTask(this.resource, async () => { if (emailAddress) { - await this.create({ identifier: emailAddress }); + await this._create({ identifier: emailAddress }); } const emailCodeFactor = this.selectFirstFactor({ strategy: 'email_code', emailAddressId }); @@ -785,7 +789,7 @@ class SignInFuture implements SignInFutureResource { return runAsyncResourceTask(this.resource, async () => { if (emailAddress) { - await this.create({ identifier: emailAddress }); + await this._create({ identifier: emailAddress }); } const emailLinkFactor = this.selectFirstFactor({ strategy: 'email_link', emailAddressId }); @@ -848,7 +852,7 @@ class SignInFuture implements SignInFutureResource { return runAsyncResourceTask(this.resource, async () => { if (phoneNumber) { - await this.create({ identifier: phoneNumber }); + await this._create({ identifier: phoneNumber }); } const phoneCodeFactor = this.selectFirstFactor({ strategy: 'phone_code', phoneNumberId }); @@ -880,14 +884,19 @@ class SignInFuture implements SignInFutureResource { throw new Error('modal flow is not supported yet'); } - if (!this.resource.id) { - await this.create({ - strategy, - redirectUrl: SignIn.clerk.buildUrlWithAuth(redirectCallbackUrl), - actionCompleteRedirectUrl: redirectUrl, - }); + let actionCompleteRedirectUrl = redirectUrl; + try { + new URL(redirectUrl); + } catch { + actionCompleteRedirectUrl = window.location.origin + redirectUrl; } + await this._create({ + strategy, + redirectUrl: SignIn.clerk.buildUrlWithAuth(redirectCallbackUrl), + actionCompleteRedirectUrl, + }); + const { status, externalVerificationRedirectURL } = this.resource.firstFactorVerification; if (status === 'unverified' && externalVerificationRedirectURL) { @@ -924,7 +933,7 @@ class SignInFuture implements SignInFutureResource { throw new Error(`Unsupported Web3 provider: ${provider}`); } - await this.create({ identifier }); + await this._create({ identifier }); const web3FirstFactor = this.resource.supportedFirstFactors?.find( f => f.strategy === strategy, diff --git a/packages/clerk-js/src/core/resources/SignUp.ts b/packages/clerk-js/src/core/resources/SignUp.ts index 35023047767..bac10783b6e 100644 --- a/packages/clerk-js/src/core/resources/SignUp.ts +++ b/packages/clerk-js/src/core/resources/SignUp.ts @@ -660,20 +660,24 @@ class SignUpFuture implements SignUpFutureResource { return { captchaToken, captchaWidgetType, captchaError }; } - async create(params: SignUpFutureCreateParams): Promise<{ error: unknown }> { - return runAsyncResourceTask(this.resource, async () => { - const { captchaToken, captchaWidgetType, captchaError } = await this.getCaptchaToken(); + private async _create(params: SignUpFutureCreateParams): Promise { + const { captchaToken, captchaWidgetType, captchaError } = await this.getCaptchaToken(); + + const body: Record = { + transfer: params.transfer, + captchaToken, + captchaWidgetType, + captchaError, + ...params, + unsafeMetadata: params.unsafeMetadata ? normalizeUnsafeMetadata(params.unsafeMetadata) : undefined, + }; - const body: Record = { - transfer: params.transfer, - captchaToken, - captchaWidgetType, - captchaError, - ...params, - unsafeMetadata: params.unsafeMetadata ? normalizeUnsafeMetadata(params.unsafeMetadata) : undefined, - }; + await this.resource.__internal_basePost({ path: this.resource.pathRoot, body }); + } - await this.resource.__internal_basePost({ path: this.resource.pathRoot, body }); + async create(params: SignUpFutureCreateParams): Promise<{ error: unknown }> { + return runAsyncResourceTask(this.resource, async () => { + await this._create(params); }); } @@ -756,12 +760,20 @@ class SignUpFuture implements SignUpFutureResource { const { strategy, redirectUrl, redirectCallbackUrl } = params; return runAsyncResourceTask(this.resource, async () => { const { captchaToken, captchaWidgetType, captchaError } = await this.getCaptchaToken(); + + let redirectUrlComplete = redirectUrl; + try { + new URL(redirectUrl); + } catch { + redirectUrlComplete = window.location.origin + redirectUrl; + } + await this.resource.__internal_basePost({ path: this.resource.pathRoot, body: { strategy, redirectUrl: SignUp.clerk.buildUrlWithAuth(redirectCallbackUrl), - redirectUrlComplete: redirectUrl, + redirectUrlComplete, captchaToken, captchaWidgetType, captchaError, @@ -808,7 +820,7 @@ class SignUpFuture implements SignUpFutureResource { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const web3Wallet = identifier || this.resource.web3wallet!; - await this.create({ web3Wallet, unsafeMetadata, legalAccepted }); + await this._create({ web3Wallet, unsafeMetadata, legalAccepted }); await this.resource.__internal_basePost({ body: { strategy }, action: 'prepare_verification', diff --git a/packages/types/src/signInFuture.ts b/packages/types/src/signInFuture.ts index 343e1320f8d..90d76506880 100644 --- a/packages/types/src/signInFuture.ts +++ b/packages/types/src/signInFuture.ts @@ -15,14 +15,14 @@ export interface SignInFutureCreateParams { export type SignInFuturePasswordParams = | { - identifier: string; password: string; - email?: never; + identifier: string; + emailAddress?: never; phoneNumber?: never; } | { password: string; - email: string; + emailAddress: string; identifier?: never; phoneNumber?: never; } @@ -30,13 +30,13 @@ export type SignInFuturePasswordParams = password: string; phoneNumber: string; identifier?: never; - email?: never; + emailAddress?: never; } | { password: string; phoneNumber?: never; identifier?: never; - email?: never; + emailAddress?: never; }; export type SignInFutureEmailCodeSendParams = diff --git a/packages/types/src/signUpFuture.ts b/packages/types/src/signUpFuture.ts index f33a0764ecb..660d5622f5f 100644 --- a/packages/types/src/signUpFuture.ts +++ b/packages/types/src/signUpFuture.ts @@ -11,6 +11,9 @@ interface SignUpFutureAdditionalParams { } export interface SignUpFutureCreateParams extends SignUpFutureAdditionalParams { + emailAddress?: string; + phoneNumber?: string; + username?: string; transfer?: boolean; ticket?: string; web3Wallet?: string;