Skip to content

Commit

Permalink
update checks
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcarpenter committed Dec 16, 2024
1 parent 37f3f57 commit 79cadb9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
14 changes: 9 additions & 5 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LocalStorageBroadcastChannel } from '@clerk/shared/localStorageBroadcas
import { logger } from '@clerk/shared/logger';
import { isHttpOrHttps, isValidProxyUrl, proxyUrlToAbsoluteURL } from '@clerk/shared/proxy';
import { eventPrebuiltComponentMounted, TelemetryCollector } from '@clerk/shared/telemetry';
import { addClerkPrefix, stripScheme } from '@clerk/shared/url';
import { addClerkPrefix, isAbsoluteUrl, stripScheme } from '@clerk/shared/url';
import { handleValueOrFn, noop } from '@clerk/shared/utils';
import type {
__internal_UserVerificationModalProps,
Expand Down Expand Up @@ -365,8 +365,8 @@ export class Clerk implements ClerkInterface {
}
};

#isCombinedFlow(): boolean {
return !this.#options.signUpUrl;
#isCombinedSignInOrUpFlow(): boolean {
return Boolean(!this.#options.signUpUrl && this.#options.signInUrl && !isAbsoluteUrl(this.#options.signInUrl));
}

public signOut: SignOut = async (callbackOrOptions?: SignOutCallback | SignOutOptions, options?: SignOutOptions) => {
Expand Down Expand Up @@ -2112,13 +2112,17 @@ export class Clerk implements ClerkInterface {
return '';
}

const signInOrUpUrl = this.#options[key] || this.environment.displayConfig[key];
let signInOrUpUrl = this.#options[key] || this.environment.displayConfig[key];
if (this.#isCombinedSignInOrUpFlow()) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- The isCombinedSignInOrUpFlow() function checks for the existence of signInUrl
signInOrUpUrl = this.#options.signInUrl!;
}
const redirectUrls = new RedirectUrls(this.#options, options).toSearchParams();
const initValues = new URLSearchParams(_initValues || {});
const url = buildURL(
{
base: signInOrUpUrl,
hashPath: this.#isCombinedFlow() && key === 'signUpUrl' ? '/create' : '',
hashPath: this.#isCombinedSignInOrUpFlow() && key === 'signUpUrl' ? '/create' : '',
hashSearchParams: [initValues, redirectUrls],
},
{ stringify: true },
Expand Down
4 changes: 1 addition & 3 deletions packages/clerk-js/src/ui/components/SignIn/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { SignInEmailLinkFlowComplete, SignUpEmailLinkFlowComplete } from '../../
import {
SignInContext,
SignUpContext,
useOptions,
useSignInContext,
useSignUpContext,
withCoreSessionSwitchGuard,
Expand Down Expand Up @@ -37,7 +36,6 @@ function RedirectToSignIn() {
function SignInRoutes(): JSX.Element {
const signInContext = useSignInContext();
const signUpContext = useSignUpContext();
const options = useOptions();

return (
<Flow.Root flow='signIn'>
Expand Down Expand Up @@ -76,7 +74,7 @@ function SignInRoutes(): JSX.Element {
redirectUrl='../factor-two'
/>
</Route>
{options.experimental?.combinedFlow && (
{signInContext.isCombinedFlow && (
<Route path='create'>
<Route
path='verify-email-address'
Expand Down
3 changes: 2 additions & 1 deletion packages/clerk-js/src/ui/contexts/components/SignIn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useClerk } from '@clerk/shared/react';
import { isAbsoluteUrl } from '@clerk/shared/url';
import { createContext, useContext, useMemo } from 'react';

import { SIGN_IN_INITIAL_VALUE_KEYS } from '../../../core/constants';
Expand Down Expand Up @@ -33,7 +34,7 @@ export const useSignInContext = (): SignInContextType => {
const { queryParams, queryString } = useRouter();
const options = useOptions();
const clerk = useClerk();
const isCombinedFlow = !options.signUpUrl;
const isCombinedFlow = Boolean(!options.signUpUrl && options.signInUrl && !isAbsoluteUrl(options.signInUrl));

if (context === null || context.componentName !== 'SignIn') {
throw new Error(`Clerk: useSignInContext called outside of the mounted SignIn component.`);
Expand Down
3 changes: 2 additions & 1 deletion packages/clerk-js/src/ui/contexts/components/SignUp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useClerk } from '@clerk/shared/react';
import { isAbsoluteUrl } from '@clerk/shared/url';
import { createContext, useContext, useMemo } from 'react';

import { SIGN_UP_INITIAL_VALUE_KEYS } from '../../../core/constants';
Expand Down Expand Up @@ -32,7 +33,7 @@ export const useSignUpContext = (): SignUpContextType => {
const { queryParams, queryString } = useRouter();
const options = useOptions();
const clerk = useClerk();
const isCombinedFlow = !options.signUpUrl;
const isCombinedFlow = Boolean(!options.signUpUrl && options.signInUrl && !isAbsoluteUrl(options.signInUrl));

const initialValuesFromQueryParams = useMemo(
() => getInitialValuesFromQueryParams(queryString, SIGN_UP_INITIAL_VALUE_KEYS),
Expand Down

0 comments on commit 79cadb9

Please sign in to comment.