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
35 changes: 35 additions & 0 deletions .changeset/bright-dragons-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
"@clerk/clerk-react": major
---

Replace the `signOutCallback` prop on the `<SignOutButton />` with `redirectUrl`. This aligns the API surface with other UI components provided by `@clerk/clerk-react`.

If you previously used the `signOutCallback` prop to navigate to another page, you can migrate as shown below.

Before:

```jsx
import { SignOutButton } from "@clerk/clerk-react";

export const Signout = () => {
return (
<SignOutButton signOutCallback={() => { window.location.href = "/your-path" }}>
<button>Sign Out</button>
</SignOutButton>
)
}
```

After:

```jsx
import { SignOutButton } from "@clerk/clerk-react";

export const Signout = () => {
return (
<SignOutButton redirectUrl="/your-path">
<button>Sign Out</button>
</SignOutButton>
)
}
```
12 changes: 8 additions & 4 deletions packages/react/src/components/SignOutButton.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import type { SignOutCallback, SignOutOptions } from '@clerk/types';
import type { SignOutOptions } from '@clerk/types';
import React from 'react';

import type { WithClerkProp } from '../types';
import { assertSingleChild, normalizeWithDefaultValue, safeExecute } from '../utils';
import { withClerk } from './withClerk';

export type SignOutButtonProps = {
signOutCallback?: SignOutCallback;
redirectUrl?: string;
signOutOptions?: SignOutOptions;
children?: React.ReactNode;
};

export const SignOutButton = withClerk(
({ clerk, children, ...props }: React.PropsWithChildren<WithClerkProp<SignOutButtonProps>>) => {
const { signOutCallback, signOutOptions, ...rest } = props;
const { redirectUrl = '/', signOutOptions, ...rest } = props;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to suggestions to moving this default to somewhere else (if necessary)

@dimkl dimkl Dec 14, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I would suggest we open a ticket and move all the defaults (we have defaults for afterSignInUrl, afterSingUpUrl) to a separate module to have all the default settings in a centralized place. For now, it seems fine to leave it there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in SDK-1079


children = normalizeWithDefaultValue(children, 'Sign out');
const child = assertSingleChild(children)('SignOutButton');

const navigateToRedirectUrl = () => {
return clerk.navigate(redirectUrl);
Comment thread
dimkl marked this conversation as resolved.
};

const clickHandler = () => {
return clerk.signOut(signOutCallback, signOutOptions);
return clerk.signOut(navigateToRedirectUrl, signOutOptions);
};

const wrappedChildClickHandler: React.MouseEventHandler = async e => {
Expand Down