From 9e6c2b6c7f62faf68c6a2d17bf157ee4c65725e2 Mon Sep 17 00:00:00 2001 From: Alex Carpenter Date: Thu, 21 Nov 2024 18:02:57 -0500 Subject: [PATCH] WIP --- packages/clerk-js/src/core/clerk.ts | 7 +++--- packages/clerk-js/src/core/constants.ts | 1 + .../src/ui/components/SignIn/SignInStart.tsx | 24 ++++++++++++------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/clerk-js/src/core/clerk.ts b/packages/clerk-js/src/core/clerk.ts index 08ba5a3be3..a7bac6c10b 100644 --- a/packages/clerk-js/src/core/clerk.ts +++ b/packages/clerk-js/src/core/clerk.ts @@ -351,7 +351,7 @@ export class Clerk implements ClerkInterface { } }; - public isCombinedFlow(): boolean { + #isCombinedFlow(): boolean { return this.#options.signInUrl === this.#options.signUpUrl; } @@ -1973,13 +1973,12 @@ export class Clerk implements ClerkInterface { } const signInOrUpUrl = this.#options[key] || this.environment.displayConfig[key]; - const combinedFlowSignUpUrl = `${this.#options.signInUrl}#/create`; - const baseUrl = this.isCombinedFlow() && key === 'signUpUrl' ? combinedFlowSignUpUrl : signInOrUpUrl; const redirectUrls = new RedirectUrls(this.#options, options).toSearchParams(); const initValues = new URLSearchParams(_initValues || {}); const url = buildURL( { - base: baseUrl, + base: signInOrUpUrl, + hashPath: this.#isCombinedFlow() && key === 'signUpUrl' ? '/create' : '', hashSearchParams: [initValues, redirectUrls], }, { stringify: true }, diff --git a/packages/clerk-js/src/core/constants.ts b/packages/clerk-js/src/core/constants.ts index ae34145cb6..488568c4e6 100644 --- a/packages/clerk-js/src/core/constants.ts +++ b/packages/clerk-js/src/core/constants.ts @@ -32,6 +32,7 @@ export const ERROR_CODES = { ENTERPRISE_SSO_EMAIL_ADDRESS_DOMAIN_MISMATCH: 'enterprise_sso_email_address_domain_mismatch', ENTERPRISE_SSO_HOSTED_DOMAIN_MISMATCH: 'enterprise_sso_hosted_domain_mismatch', SAML_EMAIL_ADDRESS_DOMAIN_MISMATCH: 'saml_email_address_domain_mismatch', + INVITATION_ACCOUNT_NOT_EXISTS: 'invitation_account_not_exists', } as const; export const SIGN_IN_INITIAL_VALUE_KEYS = ['email_address', 'phone_number', 'username']; diff --git a/packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx b/packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx index ed0531e4c5..6872151be5 100644 --- a/packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx +++ b/packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx @@ -327,18 +327,24 @@ export function _SignInStart(): JSX.Element { (e: ClerkAPIError) => e.code === ERROR_CODES.INVALID_STRATEGY_FOR_USER || e.code === ERROR_CODES.FORM_PASSWORD_INCORRECT, ); + const alreadySignedInError: ClerkAPIError = e.errors.find( (e: ClerkAPIError) => e.code === 'identifier_already_signed_in', ); + const accountDoesNotExistError: ClerkAPIError = e.errors.find( + (e: ClerkAPIError) => + e.code === ERROR_CODES.INVITATION_ACCOUNT_NOT_EXISTS || e.code === ERROR_CODES.FORM_IDENTIFIER_NOT_FOUND, + ); if (instantPasswordError) { await signInWithFields(identifierField); } else if (alreadySignedInError) { const sid = alreadySignedInError.meta!.sessionId!; await clerk.setActive({ session: sid, redirectUrl: afterSignInUrl }); - } else { - if (isCombinedFlow && userSettings.signUp.mode === SIGN_UP_MODES.WAITLIST) { - const attribute = getSignUpAttributeFromIdentifier(identifierField); + } else if (isCombinedFlow && accountDoesNotExistError) { + const attribute = getSignUpAttributeFromIdentifier(identifierField); + + if (userSettings.signUp.mode === SIGN_UP_MODES.WAITLIST) { const waitlistUrl = clerk.buildWaitlistUrl( attribute === 'emailAddress' ? { @@ -350,12 +356,14 @@ export function _SignInStart(): JSX.Element { ); return navigate(waitlistUrl); } - if (isCombinedFlow) { - const attribute = getSignUpAttributeFromIdentifier(identifierField); - clerk.client.signUp[attribute] = identifierField.value; - const createUrl = clerk.buildSignUpUrl(); - return navigate(createUrl); + + clerk.client.signUp[attribute] = identifierField.value; + const paramsToForward = new URLSearchParams(); + if (organizationTicket) { + paramsToForward.set('__clerk_ticket', organizationTicket); } + return navigate(`create?${paramsToForward.toString()}`); + } else { handleError(e, [identifierField, instantPasswordField], card.setError); } };