feat(backend): add secondFactorVerification to createSignInToken · clerk/javascript@8259d5f · GitHub
Skip to content

Commit 8259d5f

Browse files
dmoernerclaude
andcommitted
feat(backend): add secondFactorVerification to createSignInToken
A user with a second factor enabled who signs in with a sign-in token still has to complete their second factor. Some customers who issue these tokens from their backend want them to complete the sign-in without that prompt. The Backend API now accepts `second_factor_verification` on sign-in token creation (clerk/clerk_go#23112): `fresh` treats the second factor as verified at sign-in, and `stale` treats it as unverified, so a reverification that requires a second factor still prompts for one. When it is set, `expires_in_seconds` defaults to 10 minutes. This exposes it as `secondFactorVerification` on `createSignInToken()`, and makes `expiresInSeconds` optional, matching the API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3068fe9 commit 8259d5f

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions

‎packages/backend/src/api/__tests__/SignInTokenApi.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,36 @@ describe('SignInTokenAPI', () => {
4343

4444
expect(response.id).toBe('sign_in_token_123');
4545
});
46+
47+
it('sends the second factor verification as second_factor_verification', async () => {
48+
server.use(
49+
http.post(
50+
'https://api.clerk.test/v1/sign_in_tokens',
51+
validateHeaders(async ({ request }) => {
52+
const body = await request.json();
53+
expect(body).toEqual({
54+
user_id: 'user_123',
55+
second_factor_verification: 'stale',
56+
});
57+
58+
return HttpResponse.json({
59+
id: 'sign_in_token_123',
60+
user_id: 'user_123',
61+
token: 'token_123',
62+
status: 'pending',
63+
url: 'https://accounts.example.com/tickets/token_123',
64+
created_at: 1,
65+
updated_at: 1,
66+
});
67+
}),
68+
),
69+
);
70+
71+
const response = await apiClient.signInTokens.createSignInToken({
72+
userId: 'user_123',
73+
secondFactorVerification: 'stale',
74+
});
75+
76+
expect(response.id).toBe('sign_in_token_123');
77+
});
4678
});

‎packages/backend/src/api/endpoints/SignInTokenApi.ts‎

Lines changed: 4 additions & 2 deletions

0 commit comments

Comments
 (0)