Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcarpenter committed Nov 21, 2024
1 parent 368eba5 commit 9e6c2b6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
7 changes: 3 additions & 4 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class Clerk implements ClerkInterface {
}
};

public isCombinedFlow(): boolean {
#isCombinedFlow(): boolean {
return this.#options.signInUrl === this.#options.signUpUrl;
}

Expand Down Expand Up @@ -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 },
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
24 changes: 16 additions & 8 deletions packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
? {
Expand All @@ -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);
}
};
Expand Down

0 comments on commit 9e6c2b6

Please sign in to comment.