Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e34700a

Browse files
committedDec 19, 2023
chore(clerk-js,clerk-react): Consolidate afterSignOut*Url and avoid using DisplayConfig settings
1 parent f0a480f commit e34700a

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed
 

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import { withRedirectToAfterSignIn } from '../../common';
2-
import { useEnvironment, useSignInContext } from '../../contexts';
2+
import { useEnvironment, useSignInContext, useSignOutContext } from '../../contexts';
33
import { Col, descriptors, Flow, Icon } from '../../customizables';
44
import { Card, Header, PreviewButton, UserPreview, withCardStateProvider } from '../../elements';
55
import { ArrowBlockButton } from '../../elements/ArrowBlockButton';
66
import { useCardState } from '../../elements/contexts';
77
import { Plus, SignOutDouble } from '../../icons';
8-
import { useRouter } from '../../router';
98
import { useMultisessionActions } from '../UserButton/useMultisessionActions';
109

1110
const _SignInAccountSwitcher = () => {
1211
const card = useCardState();
13-
const { navigate } = useRouter();
14-
const { applicationName, userProfileUrl, signInUrl, afterSignOutAllUrl } = useEnvironment().displayConfig;
12+
const { applicationName, userProfileUrl, signInUrl } = useEnvironment().displayConfig;
1513
const { navigateAfterSignIn } = useSignInContext();
14+
const { navigateAfterSignOut } = useSignOutContext();
1615
const { handleSignOutAllClicked, handleSessionClicked, activeSessions, handleAddAccountClicked } =
1716
useMultisessionActions({
18-
navigateAfterSignOut: () => navigate(afterSignOutAllUrl),
17+
navigateAfterSignOut: navigateAfterSignOut,
1918
navigateAfterSwitchSession: navigateAfterSignIn,
2019
userProfileUrl,
2120
signInUrl,

‎packages/clerk-js/src/ui/components/UserProfile/DeleteUserPage.tsx

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
import { useClerk, useUser } from '@clerk/shared/react';
1+
import { useUser } from '@clerk/shared/react';
22

3-
import { useEnvironment } from '../../contexts';
3+
import { useSignOutContext } from '../../contexts';
44
import { Col, localizationKeys, Text } from '../../customizables';
55
import { Form, FormButtons, FormContent, useCardState, withCardStateProvider } from '../../elements';
66
import { useActionContext } from '../../elements/Action/ActionRoot';
7-
import { useRouter } from '../../router';
87
import { handleError, useFormControl } from '../../utils';
98
import { UserProfileBreadcrumbs } from './UserProfileNavbar';
109

1110
export const DeleteUserForm = withCardStateProvider(() => {
1211
const card = useCardState();
1312
const { close } = useActionContext();
14-
const environment = useEnvironment();
15-
const router = useRouter();
13+
const { navigateAfterSignOut } = useSignOutContext();
1614
const { user } = useUser();
17-
const clerk = useClerk();
1815

1916
const deleteUser = async () => {
2017
try {
@@ -23,11 +20,7 @@ export const DeleteUserForm = withCardStateProvider(() => {
2320
}
2421

2522
await user.delete();
26-
if (clerk.client.activeSessions.length > 0) {
27-
await router.navigate(environment.displayConfig.afterSignOutOneUrl);
28-
} else {
29-
await router.navigate(environment.displayConfig.afterSignOutAllUrl);
30-
}
23+
await navigateAfterSignOut();
3124
} catch (e) {
3225
handleError(e, [], card.setError);
3326
}

‎packages/clerk-js/src/ui/contexts/ClerkUIComponentsContext.tsx

+16-3
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,19 @@ export const useSignInContext = (): SignInContextType => {
184184
};
185185
};
186186

187+
export type SignOutContextType = {
188+
navigateAfterSignOut: () => any;
189+
};
190+
191+
export const useSignOutContext = (): SignOutContextType => {
192+
const { navigate } = useRouter();
193+
const clerk = useClerk();
194+
195+
const navigateAfterSignOut = () => navigate(clerk.buildAfterSignOutUrl());
196+
197+
return { navigateAfterSignOut };
198+
};
199+
187200
type PagesType = {
188201
routes: NavbarRoute[];
189202
contents: CustomPageContent[];
@@ -229,12 +242,12 @@ export const useUserButtonContext = () => {
229242
const signInUrl = pickRedirectionProp('signInUrl', { ctx, options, displayConfig }, false);
230243
const userProfileUrl = ctx.userProfileUrl || displayConfig.userProfileUrl;
231244

232-
const afterMultiSessionSingleSignOutUrl = ctx.afterMultiSessionSingleSignOutUrl || displayConfig.afterSignOutOneUrl;
233-
const navigateAfterMultiSessionSingleSignOut = () => clerk.redirectWithAuth(afterMultiSessionSingleSignOutUrl);
234-
235245
const afterSignOutUrl = ctx.afterSignOutUrl || clerk.buildAfterSignOutUrl();
236246
const navigateAfterSignOut = () => navigate(afterSignOutUrl);
237247

248+
const afterMultiSessionSingleSignOutUrl = ctx.afterMultiSessionSingleSignOutUrl || afterSignOutUrl;
249+
const navigateAfterMultiSessionSingleSignOut = () => clerk.redirectWithAuth(afterMultiSessionSingleSignOutUrl);
250+
238251
const afterSwitchSessionUrl = ctx.afterSwitchSessionUrl || displayConfig.afterSwitchSessionUrl;
239252
const navigateAfterSwitchSession = () => navigate(afterSwitchSessionUrl);
240253

‎packages/react/src/components/controlComponents.tsx

+2-6
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,11 @@ export const Protect = ({ children, fallback, ...restAuthorizedParams }: Protect
143143

144144
export const RedirectToSignIn = withClerk(({ clerk, ...props }: WithClerkProp<RedirectToSignInProps>) => {
145145
const { client, session } = clerk;
146-
// TODO: Remove temp use of __unstable__environment
147-
const { __unstable__environment } = clerk as any;
148-
149146
const hasActiveSessions = client.activeSessions && client.activeSessions.length > 0;
150147

151148
React.useEffect(() => {
152-
if (session === null && hasActiveSessions && __unstable__environment) {
153-
const { afterSignOutOneUrl } = __unstable__environment.displayConfig;
154-
void clerk.navigate(afterSignOutOneUrl);
149+
if (session === null && hasActiveSessions) {
150+
void clerk.redirectToAfterSignOut();
155151
} else {
156152
void clerk.redirectToSignIn(props);
157153
}

0 commit comments

Comments
 (0)