Skip to content

Commit f78f4c5

Browse files
committed
refactor(shared): Replace if with a switch
1 parent 57fb44f commit f78f4c5

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

packages/shared/src/authorization.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -303,25 +303,29 @@ const resolveSignedInAuthStateFromJWTClaims = (claims: JwtPayload): SignedInAuth
303303
let orgId: string | undefined;
304304
let orgRole: OrganizationCustomRoleKey | undefined;
305305
let orgSlug: string | undefined;
306+
let orgPermissions: string[] | undefined;
306307

307308
// fva can be undefined for instances that have not opt-in
308309
const factorVerificationAge = claims.fva ?? null;
309310

310311
// sts can be undefined for instances that have not opt-in
311312
const sessionStatus = claims.sts ?? null;
312313

313-
// TODO(jwt-v2): replace this when the new claim for org permissions is added, this will not break
314-
// anything since the JWT v2 is not yet available
315-
const orgPermissions = claims.v === 2 ? undefined : claims.org_permissions;
316-
317-
if (claims.v === 2) {
318-
orgId = claims.org?.id;
319-
orgRole = claims.org?.rol;
320-
orgSlug = claims.org?.slg;
321-
} else {
322-
orgId = claims.org_id;
323-
orgRole = claims.org_role;
324-
orgSlug = claims.org_slug;
314+
switch (claims.v) {
315+
case 2:
316+
orgId = claims.org?.id;
317+
orgRole = claims.org?.rol;
318+
orgSlug = claims.org?.slg;
319+
320+
// TODO(jwt-v2): when JWT version 2 is available, do proper handling for org permissions
321+
orgPermissions = (claims?.org_permissions as string[] | undefined) ?? undefined;
322+
break;
323+
default:
324+
orgId = claims.org_id;
325+
orgRole = claims.org_role;
326+
orgSlug = claims.org_slug;
327+
orgPermissions = claims.org_permissions;
328+
break;
325329
}
326330

327331
return {

0 commit comments

Comments
 (0)