Skip to content

Commit 46faeb6

Browse files
authoredNov 14, 2024··
chore(types,shared): Update reverification config values to snake_case (#4556)
1 parent 3353935 commit 46faeb6

File tree

7 files changed

+58
-37
lines changed

7 files changed

+58
-37
lines changed
 

‎.changeset/mean-foxes-protect.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@clerk/shared': minor
3+
'@clerk/types': minor
4+
---
5+
6+
Update reverification config values to snake_case.
7+
8+
For `__experimental_ReverificationConfig`
9+
- `strictMfa` changes to `strict_mfa`
10+
11+
For `__experimental_SessionVerificationLevel`
12+
- `firstFactor` changes to `first_factor`
13+
- - `secondFactor` changes to `second_factor`
14+
- - `multiFactor` changes to `multi_factor`

‎integration/templates/next-app-router/src/app/(reverification)/actions.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
import { auth } from '@clerk/nextjs/server';
44
import { __experimental_reverificationMismatch as reverificationMismatch } from '@clerk/shared/authorization-errors';
5+
import { __experimental_ReverificationConfig } from '@clerk/types';
56

67
const logUserIdActionReverification = async () => {
78
const { userId, has } = await auth.protect();
89

910
const config = {
10-
level: 'secondFactor',
11+
level: 'second_factor',
1112
afterMinutes: 1,
12-
} as const;
13+
} satisfies __experimental_ReverificationConfig;
1314

1415
const userNeedsReverification = !has({
1516
__experimental_reverification: config,

‎packages/clerk-js/src/core/resources/__tests__/Session.test.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ describe('Session', () => {
312312
const isAuthorized = session.checkAuthorization({
313313
permission: 'org:sys_profile:delete',
314314
__experimental_reverification: {
315-
level: 'multiFactor',
315+
level: 'multi_factor',
316316
afterMinutes: 10,
317317
},
318318
});
@@ -339,7 +339,7 @@ describe('Session', () => {
339339
const isAuthorized = session.checkAuthorization({
340340
permission: 'org:sys_profile:delete',
341341
__experimental_reverification: {
342-
level: 'multiFactor',
342+
level: 'multi_factor',
343343
afterMinutes: 10,
344344
},
345345
});
@@ -363,7 +363,7 @@ describe('Session', () => {
363363

364364
const isAuthorized = session.checkAuthorization({
365365
__experimental_reverification: {
366-
level: 'multiFactor',
366+
level: 'multi_factor',
367367
afterMinutes: 10,
368368
},
369369
});
@@ -387,7 +387,7 @@ describe('Session', () => {
387387

388388
const isAuthorized = session.checkAuthorization({
389389
__experimental_reverification: {
390-
level: 'multiFactor',
390+
level: 'multi_factor',
391391
afterMinutes: 10,
392392
},
393393
});
@@ -411,7 +411,7 @@ describe('Session', () => {
411411

412412
const isAuthorized = session.checkAuthorization({
413413
__experimental_reverification: {
414-
level: 'multiFactor',
414+
level: 'multi_factor',
415415
afterMinutes: 10,
416416
},
417417
});
@@ -435,7 +435,7 @@ describe('Session', () => {
435435

436436
const isAuthorized = session.checkAuthorization({
437437
__experimental_reverification: {
438-
level: 'multiFactor',
438+
level: 'multi_factor',
439439
afterMinutes: 10,
440440
},
441441
});
@@ -459,7 +459,7 @@ describe('Session', () => {
459459

460460
const isAuthorized = session.checkAuthorization({
461461
__experimental_reverification: {
462-
level: 'multiFactor',
462+
level: 'multi_factor',
463463
afterMinutes: 10,
464464
},
465465
});
@@ -503,7 +503,7 @@ describe('Session', () => {
503503
} as SessionJSON);
504504

505505
const isAuthorized = session.checkAuthorization({
506-
__experimental_reverification: 'strictMfa',
506+
__experimental_reverification: 'strict_mfa',
507507
});
508508

509509
expect(isAuthorized).toBe(true);
@@ -525,7 +525,7 @@ describe('Session', () => {
525525

526526
const isAuthorized = session.checkAuthorization({
527527
__experimental_reverification: {
528-
level: 'multiFactor',
528+
level: 'multi_factor',
529529
afterMinutes: 10,
530530
},
531531
});
@@ -549,7 +549,7 @@ describe('Session', () => {
549549

550550
const isAuthorized = session.checkAuthorization({
551551
__experimental_reverification: {
552-
level: 'multiFactor',
552+
level: 'multi_factor',
553553
afterMinutes: 10,
554554
},
555555
});
@@ -645,7 +645,7 @@ describe('Session', () => {
645645

646646
const isAuthorized = session.checkAuthorization({
647647
__experimental_reverification: {
648-
level: 'firstFactor',
648+
level: 'first_factor',
649649
afterMinutes: 10,
650650
},
651651
});
@@ -786,7 +786,7 @@ describe('Session', () => {
786786

787787
const isAuthorized = session.checkAuthorization({
788788
__experimental_reverification: {
789-
level: 'firstFactor',
789+
level: 'first_factor',
790790
//@ts-expect-error
791791
afterMinutes: '10',
792792
},
@@ -814,15 +814,15 @@ describe('Session', () => {
814814

815815
const isAuthorized = session.checkAuthorization({
816816
__experimental_reverification: {
817-
level: 'multiFactor',
817+
level: 'multi_factor',
818818
afterMinutes: 10,
819819
},
820820
});
821821

822822
expect(isAuthorized).toBe(false);
823823
});
824824

825-
it('first factor not enrolled should NOT be authorized for firstFactor assurance', async () => {
825+
it('first factor not enrolled should NOT be authorized for first_factor assurance', async () => {
826826
const session = new Session({
827827
status: 'active',
828828
id: 'session_1',
@@ -838,7 +838,7 @@ describe('Session', () => {
838838

839839
const isAuthorized = session.checkAuthorization({
840840
__experimental_reverification: {
841-
level: 'firstFactor',
841+
level: 'first_factor',
842842
afterMinutes: 10,
843843
},
844844
});

‎packages/clerk-js/src/ui/components/UserVerification/useUserVerificationSession.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useSession } from '@clerk/shared/react';
2+
import type { __experimental_SessionVerificationLevel } from '@clerk/types';
23
import { useMemo } from 'react';
34

45
import { useUserVerification } from '../../contexts';
@@ -8,9 +9,10 @@ import { useFetch } from '../../hooks';
89
const useUserVerificationSessionKey = () => {
910
const { level } = useUserVerification();
1011
return useMemo(
11-
() => ({
12-
level: level || 'secondFactor',
13-
}),
12+
() =>
13+
({
14+
level: level || 'second_factor',
15+
}) satisfies { level: __experimental_SessionVerificationLevel },
1416
[level],
1517
);
1618
};

‎packages/react/src/hooks/__tests__/useAuth.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('useAuth type tests', () => {
2929
expectTypeOf({
3030
role: 'org:admin',
3131
__experimental_reverification: {
32-
level: 'firstFactor',
32+
level: 'first_factor',
3333
afterMinutes: 10,
3434
},
3535
} as const).toMatchTypeOf<ParamsOfHas>();
@@ -39,7 +39,7 @@ describe('useAuth type tests', () => {
3939
expectTypeOf({
4040
permission: 'org:edit:posts',
4141
__experimental_reverification: {
42-
level: 'firstFactor',
42+
level: 'first_factor',
4343
afterMinutes: 10,
4444
},
4545
} as const).toMatchTypeOf<ParamsOfHas>();
@@ -48,7 +48,7 @@ describe('useAuth type tests', () => {
4848
it('has({reverification: {level, maxAge}}) is allowed', () => {
4949
expectTypeOf({
5050
__experimental_reverification: {
51-
level: 'firstFactor',
51+
level: 'first_factor',
5252
afterMinutes: 10,
5353
},
5454
} as const).toMatchTypeOf<ParamsOfHas>();
@@ -57,15 +57,15 @@ describe('useAuth type tests', () => {
5757
it('reverification with other values as maxAge should throw', () => {
5858
expectTypeOf({
5959
__experimental_reverification: {
60-
level: 'firstFactor',
60+
level: 'first_factor',
6161
afterMinutes: '10',
6262
},
6363
} as const).not.toMatchTypeOf<ParamsOfHas>();
6464
});
6565

6666
it('veryStrict reverification is allowed', () => {
6767
expectTypeOf({
68-
__experimental_reverification: 'strictMfa',
68+
__experimental_reverification: 'strict_mfa',
6969
} as const).toMatchTypeOf<ParamsOfHas>();
7070
});
7171

‎packages/shared/src/authorization.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,31 @@ type CheckStepUpAuthorization = (
3232
) => boolean | null;
3333

3434
const TYPES_TO_OBJECTS: TypesToConfig = {
35-
strictMfa: {
35+
strict_mfa: {
3636
afterMinutes: 10,
37-
level: 'multiFactor',
37+
level: 'multi_factor',
3838
},
3939
strict: {
4040
afterMinutes: 10,
41-
level: 'secondFactor',
41+
level: 'second_factor',
4242
},
4343
moderate: {
4444
afterMinutes: 60,
45-
level: 'secondFactor',
45+
level: 'second_factor',
4646
},
4747
lax: {
4848
afterMinutes: 1_440,
49-
level: 'secondFactor',
49+
level: 'second_factor',
5050
},
5151
};
5252

53-
const ALLOWED_LEVELS = new Set<__experimental_SessionVerificationLevel>(['firstFactor', 'secondFactor', 'multiFactor']);
53+
const ALLOWED_LEVELS = new Set<__experimental_SessionVerificationLevel>([
54+
'first_factor',
55+
'second_factor',
56+
'multi_factor',
57+
]);
5458

55-
const ALLOWED_TYPES = new Set<__experimental_SessionVerificationTypes>(['strictMfa', 'strict', 'moderate', 'lax']);
59+
const ALLOWED_TYPES = new Set<__experimental_SessionVerificationTypes>(['strict_mfa', 'strict', 'moderate', 'lax']);
5660

5761
// Helper functions
5862
const isValidMaxAge = (maxAge: any) => typeof maxAge === 'number' && maxAge > 0;
@@ -126,11 +130,11 @@ const checkStepUpAuthorization: CheckStepUpAuthorization = (params, { __experime
126130
const isValidFactor2 = factor2Age !== -1 ? afterMinutes > factor2Age : null;
127131

128132
switch (level) {
129-
case 'firstFactor':
133+
case 'first_factor':
130134
return isValidFactor1;
131-
case 'secondFactor':
135+
case 'second_factor':
132136
return factor2Age !== -1 ? isValidFactor2 : isValidFactor1;
133-
case 'multiFactor':
137+
case 'multi_factor':
134138
return factor2Age === -1 ? isValidFactor1 : isValidFactor1 && isValidFactor2;
135139
}
136140
};

‎packages/types/src/sessionVerification.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface __experimental_SessionVerificationResource extends ClerkResourc
1515

1616
export type __experimental_SessionVerificationStatus = 'needs_first_factor' | 'needs_second_factor' | 'complete';
1717

18-
export type __experimental_SessionVerificationTypes = 'strictMfa' | 'strict' | 'moderate' | 'lax';
18+
export type __experimental_SessionVerificationTypes = 'strict_mfa' | 'strict' | 'moderate' | 'lax';
1919

2020
export type __experimental_ReverificationConfig =
2121
| __experimental_SessionVerificationTypes
@@ -24,7 +24,7 @@ export type __experimental_ReverificationConfig =
2424
afterMinutes: __experimental_SessionVerificationAfterMinutes;
2525
};
2626

27-
export type __experimental_SessionVerificationLevel = 'firstFactor' | 'secondFactor' | 'multiFactor';
27+
export type __experimental_SessionVerificationLevel = 'first_factor' | 'second_factor' | 'multi_factor';
2828
export type __experimental_SessionVerificationAfterMinutes = number;
2929

3030
export type __experimental_SessionVerificationFirstFactor = EmailCodeFactor | PhoneCodeFactor | PasswordFactor;

0 commit comments

Comments
 (0)
Please sign in to comment.