Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/giant-cats-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': minor
'@clerk/types': minor
---

[Experimental] Fix `signIn.password` emailAddress parameter name.
6 changes: 6 additions & 0 deletions .changeset/purple-toys-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': minor
'@clerk/types': minor
---

[Experimental] Fix issue where calling `this.create()` would not correctly propagate errors.
43 changes: 26 additions & 17 deletions packages/clerk-js/src/core/resources/SignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,23 +703,27 @@ class SignInFuture implements SignInFutureResource {
});
}

private async _create(params: SignInFutureCreateParams): Promise<void> {
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,
Expand All @@ -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 });
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
40 changes: 26 additions & 14 deletions packages/clerk-js/src/core/resources/SignUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
const { captchaToken, captchaWidgetType, captchaError } = await this.getCaptchaToken();

const body: Record<string, unknown> = {
transfer: params.transfer,
captchaToken,
captchaWidgetType,
captchaError,
...params,
unsafeMetadata: params.unsafeMetadata ? normalizeUnsafeMetadata(params.unsafeMetadata) : undefined,
};

const body: Record<string, unknown> = {
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);
});
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down
10 changes: 5 additions & 5 deletions packages/types/src/signInFuture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ 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;
}
| {
password: string;
phoneNumber: string;
identifier?: never;
email?: never;
emailAddress?: never;
}
| {
password: string;
phoneNumber?: never;
identifier?: never;
email?: never;
emailAddress?: never;
};

export type SignInFutureEmailCodeSendParams =
Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/signUpFuture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ interface SignUpFutureAdditionalParams {
}

export interface SignUpFutureCreateParams extends SignUpFutureAdditionalParams {
emailAddress?: string;
phoneNumber?: string;
username?: string;
transfer?: boolean;
ticket?: string;
web3Wallet?: string;
Expand Down
Loading