Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(clerk-js,react,types): Add option to enable combined flow at component level #4799

Open
wants to merge 2 commits into
base: alexcarpenter/sign-in-or-up-ga
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .changeset/cuddly-shrimps-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/clerk-js': patch
'@clerk/clerk-react': patch
'@clerk/types': patch
---

Add option to allow a `<SignIn />` component instance to opt into the combined flow.
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
Loading