Skip to content

Commit 6b35b89

Browse files
committed
feat(clerk-js): Use Account Portal for popup callback
1 parent b672410 commit 6b35b89

File tree

6 files changed

+16
-65
lines changed

6 files changed

+16
-65
lines changed

packages/clerk-js/src/core/clerk.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -1752,13 +1752,22 @@ export class Clerk implements ClerkInterface {
17521752
};
17531753

17541754
public authenticateWithPopup = async (
1755-
params: AuthenticateWithRedirectParams & { popupCallbackUrl: string; popup: Window | null },
1755+
params: AuthenticateWithRedirectParams & { popup: Window | null },
17561756
): Promise<void> => {
17571757
if (!this.client || !this.environment || !params.popup) {
17581758
return;
17591759
}
17601760

1761-
const { redirectUrl, popupCallbackUrl } = params;
1761+
const accountPortalDomain = this.frontendApi
1762+
// staging accounts
1763+
.replace(/clerk\.accountsstage\./, 'accountsstage.')
1764+
.replace(/clerk\.accounts\.|clerk\./, 'accounts.');
1765+
1766+
const { redirectUrl } = params;
1767+
1768+
const popupRedirectUrlComplete = `https://${accountPortalDomain}/popup-callback`;
1769+
const popupRedirectUrl = `https://${accountPortalDomain}/popup-callback?destination=${encodeURIComponent(redirectUrl)}`;
1770+
17621771
window.addEventListener('message', async event => {
17631772
if (event.origin !== window.location.origin) return;
17641773
if (event.data.session) {
@@ -1775,7 +1784,8 @@ export class Clerk implements ClerkInterface {
17751784
});
17761785
await this.client.signIn.authenticateWithPopup({
17771786
...params,
1778-
redirectUrlComplete: popupCallbackUrl,
1787+
redirectUrlComplete: popupRedirectUrlComplete,
1788+
redirectUrl: popupRedirectUrl,
17791789
});
17801790
};
17811791

packages/clerk-js/src/ui/common/redirects.ts

-14
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,6 @@ export function buildSSOCallbackURL(
3939
});
4040
}
4141

42-
export function buildPopupCallbackURL(
43-
ctx: Partial<SignInContextType | SignUpContextType>,
44-
baseUrl: string | undefined = '',
45-
): string {
46-
const { routing, authQueryString, path } = ctx;
47-
return buildRedirectUrl({
48-
routing,
49-
baseUrl,
50-
authQueryString,
51-
path,
52-
endpoint: '/popup-callback',
53-
});
54-
}
55-
5642
type AuthQueryString = string | null | undefined;
5743

5844
type BuildRedirectUrlParams = {

packages/clerk-js/src/ui/components/SignIn/SignIn.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { ResetPasswordSuccess } from './ResetPasswordSuccess';
2424
import { SignInAccountSwitcher } from './SignInAccountSwitcher';
2525
import { SignInFactorOne } from './SignInFactorOne';
2626
import { SignInFactorTwo } from './SignInFactorTwo';
27-
import { SignInPopupCallback } from './SignInPopupCallback';
2827
import { SignInSSOCallback } from './SignInSSOCallback';
2928
import { SignInStart } from './SignInStart';
3029

@@ -68,9 +67,6 @@ function SignInRoutes(): JSX.Element {
6867
resetPasswordUrl={'../reset-password'}
6968
/>
7069
</Route>
71-
<Route path='popup-callback'>
72-
<SignInPopupCallback />
73-
</Route>
7470
<Route path='choose'>
7571
<SignInAccountSwitcher />
7672
</Route>

packages/clerk-js/src/ui/components/SignIn/SignInPopupCallback.tsx

-38
This file was deleted.

packages/clerk-js/src/ui/components/SignIn/SignInSocialButtons.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useClerk } from '@clerk/shared/react';
22
import React from 'react';
33

4-
import { buildPopupCallbackURL, buildSSOCallbackURL } from '../../common/redirects';
4+
import { buildSSOCallbackURL } from '../../common/redirects';
55
import { useSignInContext } from '../../contexts';
66
import { useEnvironment } from '../../contexts/EnvironmentContext';
77
import { useCardState } from '../../elements/contexts';
@@ -17,7 +17,6 @@ export const SignInSocialButtons = React.memo((props: SocialButtonsProps) => {
1717
const { displayConfig } = useEnvironment();
1818
const ctx = useSignInContext();
1919
const redirectUrl = buildSSOCallbackURL(ctx, displayConfig.signInUrl);
20-
const popupCallbackUrl = buildPopupCallbackURL(ctx, displayConfig.signInUrl);
2120
const redirectUrlComplete = ctx.afterSignInUrl || '/';
2221

2322
return (
@@ -26,7 +25,7 @@ export const SignInSocialButtons = React.memo((props: SocialButtonsProps) => {
2625
oauthCallback={strategy => {
2726
const popup = window.open('about:blank', '', 'width=600,height=600');
2827
return clerk
29-
.authenticateWithPopup({ strategy, redirectUrl, redirectUrlComplete, popupCallbackUrl, popup })
28+
.authenticateWithPopup({ strategy, redirectUrl, redirectUrlComplete, popup })
3029
.catch(err => handleError(err, [], card.setError));
3130
}}
3231
web3Callback={strategy => {

packages/types/src/clerk.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,7 @@ export interface Clerk {
588588
params: AuthenticateWithGoogleOneTapParams,
589589
) => Promise<SignInResource | SignUpResource>;
590590

591-
authenticateWithPopup: (
592-
params: AuthenticateWithRedirectParams & { popupCallbackUrl: string; popup: Window | null },
593-
) => Promise<unknown>;
591+
authenticateWithPopup: (params: AuthenticateWithRedirectParams & { popup: Window | null }) => Promise<unknown>;
594592

595593
/**
596594
* Creates an organization, adding the current user as admin.

0 commit comments

Comments
 (0)