Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcarpenter committed Dec 12, 2024
1 parent 85a36a8 commit fc51ef5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/clerk-js/src/ui/components/SignIn/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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? */}
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/ui/components/SignUp/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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? */}
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
Expand Up @@ -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(
Expand All @@ -53,6 +53,7 @@ export const useSignInContext = (): SignInContextType => {
signInForceRedirectUrl: ctx.forceRedirectUrl,
},
queryParams,
mode,
);

const afterSignInUrl = clerk.buildUrlWithAuth(redirectUrls.getAfterSignInUrl());
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
Expand Up @@ -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,
Expand All @@ -51,6 +51,7 @@ export const useSignUpContext = (): SignUpContextType => {
signUpForceRedirectUrl: ctx.forceRedirectUrl,
},
queryParams,
mode,
);

const afterSignUpUrl = clerk.buildUrlWithAuth(redirectUrls.getAfterSignUpUrl());
Expand Down
8 changes: 7 additions & 1 deletion packages/clerk-js/src/utils/redirectUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 || '/';
}

Expand Down

0 comments on commit fc51ef5

Please sign in to comment.