Skip to content

Commit

Permalink
feat(clerk-js,react,types): Add option to enable combined flow at com…
Browse files Browse the repository at this point in the history
…ponent level
  • Loading branch information
alexcarpenter committed Dec 17, 2024
1 parent 79cadb9 commit 9ae0630
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/clerk-js/src/ui/contexts/components/SignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ export const useSignInContext = (): SignInContextType => {
const { queryParams, queryString } = useRouter();
const options = useOptions();
const clerk = useClerk();
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.`);
}

const isCombinedFlow =
Boolean(!options.signUpUrl && options.signInUrl && !isAbsoluteUrl(options.signInUrl)) || context.combinedFlow;

const { componentName, mode, ..._ctx } = context;
const ctx = _ctx.__experimental?.combinedProps || _ctx;

Expand Down Expand Up @@ -76,7 +78,7 @@ export const useSignInContext = (): SignInContextType => {
signUpUrl = buildURL({ base: signUpUrl, hashSearchParams: [queryParams, preservedParams] }, { stringify: true });
waitlistUrl = buildURL({ base: waitlistUrl, hashSearchParams: [queryParams, preservedParams] }, { stringify: true });

if (options.experimental?.combinedFlow) {
if (isCombinedFlow) {
signUpUrl = buildURL(
{ base: signInUrl, hashPath: '/create', hashSearchParams: [queryParams, preservedParams] },
{ stringify: true },
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/components/SignInButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const SignInButton = withClerk(({ clerk, children, ...props }: WithClerkP
signUpForceRedirectUrl,
mode,
initialValues,
combinedFlow,
...rest
} = props;
children = normalizeWithDefaultValue(children, 'Sign in');
Expand All @@ -25,6 +26,7 @@ export const SignInButton = withClerk(({ clerk, children, ...props }: WithClerkP
signUpFallbackRedirectUrl,
signUpForceRedirectUrl,
initialValues,
combinedFlow,
};

if (mode === 'modal') {
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export type SignInButtonProps = ButtonProps &
| 'signUpForceRedirectUrl'
| 'signUpFallbackRedirectUrl'
| 'initialValues'
| 'combinedFlow'
>;

export type SignUpButtonProps = {
Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,10 @@ export type SignInProps = RoutingOptions & {
* Additional arbitrary metadata to be stored alongside the User object
*/
unsafeMetadata?: SignUpUnsafeMetadata;
/**
* Enable the combined sign-in-or-up flow for `<SignIn />` component instance.
*/
combinedFlow?: boolean;
} & TransferableOption &
SignUpForceRedirectUrl &
SignUpFallbackRedirectUrl &
Expand Down

0 comments on commit 9ae0630

Please sign in to comment.