Skip to content

Commit 07dcd05

Browse files
committed
chore(shared,types): Move SharedSignedInAuthObjectProperties to @clerk/types
1 parent 85f8057 commit 07dcd05

File tree

4 files changed

+32
-28
lines changed

4 files changed

+32
-28
lines changed

packages/shared/src/__tests__/jwtPayloadParser.test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ const baseClaims = {
1111
__raw: '',
1212
};
1313

14-
describe('resolveSignedInAuthStateFromJWTClaims', () => {
15-
test.skip('produced auth object is the same for v1 and v2', () => {
14+
describe('JWTPayloadToAuthObjectProperties', () => {
15+
test('produced auth object is the same for v1 and v2', () => {
1616
const { sessionClaims: v2Claims, ...signedInAuthObjectV2 } = JWTPayloadToAuthObjectProperties({
1717
...baseClaims,
1818
v: 2,
19+
fea: 'o:impersonation',
1920
o: {
2021
id: 'org_id',
2122
rol: 'admin',
2223
slg: 'org_slug',
23-
per: 'permission1,permission2',
24+
per: 'read,manage',
25+
fpm: '3',
2426
},
2527
});
2628

@@ -29,7 +31,7 @@ describe('resolveSignedInAuthStateFromJWTClaims', () => {
2931
org_id: 'org_id',
3032
org_role: 'admin',
3133
org_slug: 'org_slug',
32-
org_permissions: ['org:permission1', 'permission2'],
34+
org_permissions: ['org:impersonation:read', 'org:impersonation:manage'],
3335
});
3436
expect(signedInAuthObjectV1).toEqual(signedInAuthObjectV2);
3537
});

packages/shared/src/jwtPayloadParser.ts

+2-24
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,10 @@
11
import type {
2-
ActClaim,
32
JwtPayload,
43
OrganizationCustomPermissionKey,
54
OrganizationCustomRoleKey,
6-
SessionStatusClaim,
5+
SharedSignedInAuthObjectProperties,
76
} from '@clerk/types';
87

9-
/**
10-
* @internal
11-
*/
12-
type SignedInAuthObjectProperties = {
13-
sessionClaims: JwtPayload;
14-
sessionId: string;
15-
sessionStatus: SessionStatusClaim | null;
16-
actor: ActClaim | undefined;
17-
userId: string;
18-
orgId: string | undefined;
19-
orgRole: OrganizationCustomRoleKey | undefined;
20-
orgSlug: string | undefined;
21-
orgPermissions: OrganizationCustomPermissionKey[] | undefined;
22-
/**
23-
* Factor Verification Age
24-
* Each item represents the minutes that have passed since the last time a first or second factor were verified.
25-
* [fistFactorAge, secondFactorAge]
26-
*/
27-
factorVerificationAge: [firstFactorAge: number, secondFactorAge: number] | null;
28-
};
29-
308
const parseFeatures = (fea: string | undefined) => {
319
const features = fea ? fea.split(',').map(f => f.trim()) : [];
3210

@@ -100,7 +78,7 @@ function buildOrgPermissions({
10078
*
10179
* Resolves the signed-in auth state from JWT claims.
10280
*/
103-
const __experimental_JWTPayloadToAuthObjectProperties = (claims: JwtPayload): SignedInAuthObjectProperties => {
81+
const __experimental_JWTPayloadToAuthObjectProperties = (claims: JwtPayload): SharedSignedInAuthObjectProperties => {
10482
let orgId: string | undefined;
10583
let orgRole: OrganizationCustomRoleKey | undefined;
10684
let orgSlug: string | undefined;

packages/types/src/authObject.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { ActClaim, JwtPayload, SessionStatusClaim } from './jwtv2';
2+
import type { OrganizationCustomPermissionKey, OrganizationCustomRoleKey } from './organizationMembership';
3+
4+
/**
5+
* @internal
6+
*/
7+
export type SharedSignedInAuthObjectProperties = {
8+
sessionClaims: JwtPayload;
9+
sessionId: string;
10+
sessionStatus: SessionStatusClaim | null;
11+
actor: ActClaim | undefined;
12+
userId: string;
13+
orgId: string | undefined;
14+
orgRole: OrganizationCustomRoleKey | undefined;
15+
orgSlug: string | undefined;
16+
orgPermissions: OrganizationCustomPermissionKey[] | undefined;
17+
/**
18+
* Factor Verification Age
19+
* Each item represents the minutes that have passed since the last time a first or second factor were verified.
20+
* [fistFactorAge, secondFactorAge]
21+
*/
22+
factorVerificationAge: [firstFactorAge: number, secondFactorAge: number] | null;
23+
};

packages/types/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ export * from './customMenuItems';
6767
export * from './samlConnection';
6868
export * from './waitlist';
6969
export * from './snapshots';
70+
export * from './authObject';

0 commit comments

Comments
 (0)