From fc51ef59b32935c0d53d443d4a6c5a53b7e11ba2 Mon Sep 17 00:00:00 2001 From: Alex Carpenter Date: Thu, 12 Dec 2024 09:19:20 -0500 Subject: [PATCH] init --- packages/clerk-js/src/ui/components/SignIn/SignIn.tsx | 1 + packages/clerk-js/src/ui/components/SignUp/SignUp.tsx | 1 + packages/clerk-js/src/ui/contexts/components/SignIn.ts | 3 ++- packages/clerk-js/src/ui/contexts/components/SignUp.ts | 3 ++- packages/clerk-js/src/utils/redirectUrls.ts | 8 +++++++- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/clerk-js/src/ui/components/SignIn/SignIn.tsx b/packages/clerk-js/src/ui/components/SignIn/SignIn.tsx index fbce678921..ea783fc013 100644 --- a/packages/clerk-js/src/ui/components/SignIn/SignIn.tsx +++ b/packages/clerk-js/src/ui/components/SignIn/SignIn.tsx @@ -176,6 +176,7 @@ export const SignInModal = (props: SignInModalProps): JSX.Element => { componentName: 'SignIn', ...signInProps, routing: 'virtual', + mode: 'modal', }} > {/*TODO: Used by InvisibleRootBox, can we simplify? */} diff --git a/packages/clerk-js/src/ui/components/SignUp/SignUp.tsx b/packages/clerk-js/src/ui/components/SignUp/SignUp.tsx index e231773fc8..430ae2f53a 100644 --- a/packages/clerk-js/src/ui/components/SignUp/SignUp.tsx +++ b/packages/clerk-js/src/ui/components/SignUp/SignUp.tsx @@ -103,6 +103,7 @@ export const SignUpModal = (props: SignUpModalProps): JSX.Element => { componentName: 'SignUp', ...signUpProps, routing: 'virtual', + mode: 'modal', }} > {/*TODO: Used by InvisibleRootBox, can we simplify? */} diff --git a/packages/clerk-js/src/ui/contexts/components/SignIn.ts b/packages/clerk-js/src/ui/contexts/components/SignIn.ts index c717bec4da..e089e0f1b9 100644 --- a/packages/clerk-js/src/ui/contexts/components/SignIn.ts +++ b/packages/clerk-js/src/ui/contexts/components/SignIn.ts @@ -37,7 +37,7 @@ export const useSignInContext = (): SignInContextType => { throw new Error(`Clerk: useSignInContext called outside of the mounted SignIn component.`); } - const { componentName, ..._ctx } = context; + const { componentName, mode, ..._ctx } = context; const ctx = _ctx.__experimental?.combinedProps || _ctx; const initialValuesFromQueryParams = useMemo( @@ -53,6 +53,7 @@ export const useSignInContext = (): SignInContextType => { signInForceRedirectUrl: ctx.forceRedirectUrl, }, queryParams, + mode, ); const afterSignInUrl = clerk.buildUrlWithAuth(redirectUrls.getAfterSignInUrl()); diff --git a/packages/clerk-js/src/ui/contexts/components/SignUp.ts b/packages/clerk-js/src/ui/contexts/components/SignUp.ts index d532d527af..643525c4ef 100644 --- a/packages/clerk-js/src/ui/contexts/components/SignUp.ts +++ b/packages/clerk-js/src/ui/contexts/components/SignUp.ts @@ -41,7 +41,7 @@ export const useSignUpContext = (): SignUpContextType => { throw new Error('Clerk: useSignUpContext called outside of the mounted SignUp component.'); } - const { componentName, ...ctx } = context; + const { componentName, mode, ...ctx } = context; const redirectUrls = new RedirectUrls( options, @@ -51,6 +51,7 @@ export const useSignUpContext = (): SignUpContextType => { signUpForceRedirectUrl: ctx.forceRedirectUrl, }, queryParams, + mode, ); const afterSignUpUrl = clerk.buildUrlWithAuth(redirectUrls.getAfterSignUpUrl()); diff --git a/packages/clerk-js/src/utils/redirectUrls.ts b/packages/clerk-js/src/utils/redirectUrls.ts index b31b728cd8..704d6a1a38 100644 --- a/packages/clerk-js/src/utils/redirectUrls.ts +++ b/packages/clerk-js/src/utils/redirectUrls.ts @@ -22,12 +22,14 @@ export class RedirectUrls { private readonly fromOptions: RedirectOptions; private readonly fromProps: RedirectOptions; private readonly fromSearchParams: RedirectOptions & { redirectUrl?: string | null }; + private readonly mode?: 'modal' | 'mounted' | undefined; - constructor(options: ClerkOptions, props: RedirectOptions = {}, searchParams: any = {}) { + constructor(options: ClerkOptions, props: RedirectOptions = {}, searchParams: any = {}, mode?: undefined) { this.options = options; this.fromOptions = this.#parse(options || {}); this.fromProps = this.#parse(props || {}); this.fromSearchParams = this.#parseSearchParams(searchParams || {}); + this.mode = mode; } getAfterSignInUrl() { @@ -136,6 +138,10 @@ export class RedirectUrls { warnForNewPropShadowingLegacyProp(newKeyInUse, result, legacyPropKey, legacyValue); result ||= legacyValue; + if (!result && this.mode === 'modal') { + return window.location.href; + } + return result || '/'; }