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
17 changes: 16 additions & 1 deletion src/components/impersonation.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ describe('Impersonation', () => {
render(<Impersonation />);
const stopButton = await screen.findByText('Stop');
stopButton.click();
expect(handleSignOutAction).toHaveBeenCalled();
expect(handleSignOutAction).toHaveBeenCalledWith({});
});

it('should pass returnTo prop to handleSignOutAction when provided', async () => {
(useAuth as jest.Mock).mockReturnValue({
impersonator: { email: '[email protected]' },
user: { id: '123', email: '[email protected]' },
organizationId: null,
loading: false,
});

const returnTo = '/dashboard';
render(<Impersonation returnTo={returnTo} />);
const stopButton = await screen.findByText('Stop');
stopButton.click();
expect(handleSignOutAction).toHaveBeenCalledWith({ returnTo });
});
});
5 changes: 3 additions & 2 deletions src/components/impersonation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { useAuth } from './authkit-provider.js';

interface ImpersonationProps extends React.ComponentPropsWithoutRef<'div'> {
side?: 'top' | 'bottom';
returnTo?: string;
}

export function Impersonation({ side = 'bottom', ...props }: ImpersonationProps) {
export function Impersonation({ side = 'bottom', returnTo, ...props }: ImpersonationProps) {
const { user, impersonator, organizationId, loading } = useAuth();

const [organization, setOrganization] = React.useState<Organization | null>(null);
Expand Down Expand Up @@ -78,7 +79,7 @@ export function Impersonation({ side = 'bottom', ...props }: ImpersonationProps)
<form
onSubmit={async (event) => {
event.preventDefault();
await handleSignOutAction();
await handleSignOutAction({ returnTo });
}}
style={{
display: 'flex',
Expand Down