Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/clear-ticket-after-challenge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/ui': patch
---

Clear the invitation ticket from the URL when a sign-in completes on a verification challenge.
4 changes: 4 additions & 0 deletions packages/ui/src/components/SignIn/SignInProtectCheck.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { removeClerkQueryParam } from '@clerk/shared/internal/clerk-js/queryParams';
import { useClerk } from '@clerk/shared/react';
import type { SignInResource } from '@clerk/shared/types';
import { useEffect, useRef, useState } from 'react';
Expand Down Expand Up @@ -72,6 +73,9 @@ function SignInProtectCheckInternal(): JSX.Element | null {
return;
}
if (updatedSignIn.status === 'complete' && updatedSignIn.createdSessionId) {
// A ticket sign-in that would have completed on the start page is completing here
// instead, so the ticket has to be cleared here too — otherwise it stays in the URL.
removeClerkQueryParam('__clerk_ticket');
await setActive({
session: updatedSignIn.createdSessionId,
navigate: async ({ session, decorateUrl }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ beforeEach(() => {
});

describe('SignInProtectCheck', () => {
it('clears the invitation ticket when the sign-in completes on the challenge', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.startSignInWithProtectCheck();
});
const url = new URL(window.location.href);
url.searchParams.set('__clerk_ticket', 'tkt_abc');
window.history.replaceState({}, '', url.toString());

mockExecute.mockResolvedValue('proof-abc');
fixtures.signIn.submitProtectCheck.mockResolvedValue({
status: 'complete',
protectCheck: null,
createdSessionId: 'sess_1',
} as unknown as SignInResource);

render(<SignInProtectCheck />, { wrapper });

await waitFor(() => {
expect(fixtures.clerk.setActive).toHaveBeenCalled();
});
expect(new URL(window.location.href).searchParams.get('__clerk_ticket')).toBeNull();
});

describe('enterprise SSO', () => {
const enterpriseSSOSignIn = (supportedFirstFactors: unknown[]) =>
({
Expand Down
Loading