Skip to content

Commit

Permalink
fix(clerk-react): Make signOutOptions prop functional (#4433)
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano authored Oct 30, 2024
1 parent cdc17f0 commit 69c8f4f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/beige-bananas-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/clerk-react": patch
---

Fix `signOutOptions` prop usage in `<SignOutButton />` component
2 changes: 1 addition & 1 deletion packages/react/src/components/SignOutButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const SignOutButton = withClerk(
children = normalizeWithDefaultValue(children, 'Sign out');
const child = assertSingleChild(children)('SignOutButton');

const clickHandler = () => clerk.signOut({ redirectUrl });
const clickHandler = () => clerk.signOut({ redirectUrl, ...signOutOptions });
const wrappedChildClickHandler: React.MouseEventHandler = async e => {
await safeExecute((child as any).props.onClick)(e);
return clickHandler();
Expand Down
20 changes: 20 additions & 0 deletions packages/react/src/components/__tests__/SignOutButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jest.mock('../withClerk', () => {
};
});

const url = 'https://www.clerk.com';

describe('<SignOutButton />', () => {
beforeAll(() => {
console.error = jest.fn();
Expand All @@ -46,6 +48,24 @@ describe('<SignOutButton />', () => {
});
});

it('handles redirectUrl prop', async () => {
render(<SignOutButton redirectUrl={url} />);
const btn = screen.getByText('Sign out');
userEvent.click(btn);
await waitFor(() => {
expect(mockSignOut).toHaveBeenCalledWith({ redirectUrl: url });
});
});

it('handles signOutOptions prop', async () => {
render(<SignOutButton signOutOptions={{ redirectUrl: url, sessionId: 'sess_1yDceUR8SIKtQ0gIOO8fNsW7nhe' }} />);
const btn = screen.getByText('Sign out');
userEvent.click(btn);
await waitFor(() => {
expect(mockSignOut).toHaveBeenCalledWith({ redirectUrl: url, sessionId: 'sess_1yDceUR8SIKtQ0gIOO8fNsW7nhe' });
});
});

it('uses text passed as children', async () => {
render(<SignOutButton>text</SignOutButton>);
screen.getByText('text');
Expand Down

0 comments on commit 69c8f4f

Please sign in to comment.