Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .changeset/silly-zebras-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': major
'@clerk/clerk-react': major
---

Consolidate `afterSignOutOneUrl` & `afterSignOutAllUrl` to `afterSignOutUrl` and drop usage of Dashboard settings in ClerkJS components. The Dashboard settings should only apply to the Account Portal application.
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { withRedirectToAfterSignIn } from '../../common';
import { useEnvironment, useSignInContext } from '../../contexts';
import { useEnvironment, useSignInContext, useSignOutContext } from '../../contexts';
import { Col, descriptors, Flow, Icon } from '../../customizables';
import { Card, Header, PreviewButton, UserPreview, withCardStateProvider } from '../../elements';
import { ArrowBlockButton } from '../../elements/ArrowBlockButton';
import { useCardState } from '../../elements/contexts';
import { Plus, SignOutDouble } from '../../icons';
import { useRouter } from '../../router';
import { useMultisessionActions } from '../UserButton/useMultisessionActions';

const _SignInAccountSwitcher = () => {
const card = useCardState();
const { navigate } = useRouter();
const { applicationName, userProfileUrl, signInUrl, afterSignOutAllUrl } = useEnvironment().displayConfig;
const { applicationName, userProfileUrl, signInUrl } = useEnvironment().displayConfig;
const { navigateAfterSignIn } = useSignInContext();
const { navigateAfterSignOut } = useSignOutContext();
const { handleSignOutAllClicked, handleSessionClicked, activeSessions, handleAddAccountClicked } =
useMultisessionActions({
navigateAfterSignOut: () => navigate(afterSignOutAllUrl),
navigateAfterSignOut,
navigateAfterSwitchSession: navigateAfterSignIn,
userProfileUrl,
signInUrl,
Expand Down
15 changes: 4 additions & 11 deletions packages/clerk-js/src/ui/components/UserProfile/DeleteUserForm.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { useClerk, useUser } from '@clerk/shared/react';
import { useUser } from '@clerk/shared/react';

import { useEnvironment } from '../../contexts';
import { useSignOutContext } from '../../contexts';
import { Col, localizationKeys, Text } from '../../customizables';
import type { FormProps } from '../../elements';
import { Form, FormButtons, FormContent, useCardState, withCardStateProvider } from '../../elements';
import { useRouter } from '../../router';
import { handleError, useFormControl } from '../../utils';
import { UserProfileBreadcrumbs } from './UserProfileNavbar';

type DeleteUserFormProps = FormProps;
export const DeleteUserForm = withCardStateProvider((props: DeleteUserFormProps) => {
const { onReset } = props;
const card = useCardState();
const environment = useEnvironment();
const router = useRouter();
const { navigateAfterSignOut } = useSignOutContext();
const { user } = useUser();
const clerk = useClerk();

const deleteUser = async () => {
try {
Expand All @@ -24,11 +21,7 @@ export const DeleteUserForm = withCardStateProvider((props: DeleteUserFormProps)
}

await user.delete();
if (clerk.client.activeSessions.length > 0) {
await router.navigate(environment.displayConfig.afterSignOutOneUrl);
} else {
await router.navigate(environment.displayConfig.afterSignOutAllUrl);
}
await navigateAfterSignOut();
} catch (e) {
handleError(e, [], card.setError);
}
Expand Down
19 changes: 16 additions & 3 deletions packages/clerk-js/src/ui/contexts/ClerkUIComponentsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ export const useSignInContext = (): SignInContextType => {
};
};

export type SignOutContextType = {
navigateAfterSignOut: () => any;
};

export const useSignOutContext = (): SignOutContextType => {
const { navigate } = useRouter();
const clerk = useClerk();

const navigateAfterSignOut = () => navigate(clerk.buildAfterSignOutUrl());

return { navigateAfterSignOut };
};

type PagesType = {
routes: NavbarRoute[];
contents: CustomPageContent[];
Expand Down Expand Up @@ -229,12 +242,12 @@ export const useUserButtonContext = () => {
const signInUrl = pickRedirectionProp('signInUrl', { ctx, options, displayConfig }, false);
const userProfileUrl = ctx.userProfileUrl || displayConfig.userProfileUrl;

const afterMultiSessionSingleSignOutUrl = ctx.afterMultiSessionSingleSignOutUrl || displayConfig.afterSignOutOneUrl;
const navigateAfterMultiSessionSingleSignOut = () => clerk.redirectWithAuth(afterMultiSessionSingleSignOutUrl);

const afterSignOutUrl = ctx.afterSignOutUrl || clerk.buildAfterSignOutUrl();
const navigateAfterSignOut = () => navigate(afterSignOutUrl);

const afterMultiSessionSingleSignOutUrl = ctx.afterMultiSessionSingleSignOutUrl || afterSignOutUrl;
const navigateAfterMultiSessionSingleSignOut = () => clerk.redirectWithAuth(afterMultiSessionSingleSignOutUrl);

const afterSwitchSessionUrl = ctx.afterSwitchSessionUrl || displayConfig.afterSwitchSessionUrl;
const navigateAfterSwitchSession = () => navigate(afterSwitchSessionUrl);

Expand Down
8 changes: 2 additions & 6 deletions packages/react/src/components/controlComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,11 @@ export const Protect = ({ children, fallback, ...restAuthorizedParams }: Protect

export const RedirectToSignIn = withClerk(({ clerk, ...props }: WithClerkProp<RedirectToSignInProps>) => {
const { client, session } = clerk;
// TODO: Remove temp use of __unstable__environment
const { __unstable__environment } = clerk as any;

const hasActiveSessions = client.activeSessions && client.activeSessions.length > 0;

React.useEffect(() => {
if (session === null && hasActiveSessions && __unstable__environment) {
const { afterSignOutOneUrl } = __unstable__environment.displayConfig;
void clerk.navigate(afterSignOutOneUrl);
if (session === null && hasActiveSessions) {
void clerk.redirectToAfterSignOut();
} else {
void clerk.redirectToSignIn(props);
}
Expand Down