Skip to content

Commit fe2607b

Browse files
authoredDec 19, 2023
chore(clerk-js,types,backend): Remove MemberRole Type (#2388)
* chore(clerk-js,types,backend): Remove MemberRole Type `MemberRole` would always include the old role keys `admin`, `member`, `guest_member`. If developers still depend on them after the introduction of custom roles, the can provide them as their custom types for authorization. * chore(clerk-js): Change changeset
1 parent 72b66e1 commit fe2607b

19 files changed

+68
-60
lines changed
 

‎.changeset/orange-files-end.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/clerk-react': minor
4+
'@clerk/types': minor
5+
---
6+
7+
Remove MemberRole Type`MemberRole` would always include the old role keys `admin`, `member`, `guest_member`.
8+
If developers still depend on them after the introduction of custom roles, the can provide them as their custom types for authorization.
9+
10+
```ts
11+
// clerk.d.ts
12+
export {}
13+
14+
interface ClerkAuthorization {
15+
permission: '';
16+
role: 'admin' | 'basic_member' | 'guest_member';
17+
}
18+
```

‎packages/clerk-js/src/core/resources/OrganizationInvitation.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {
22
CreateBulkOrganizationInvitationParams,
33
CreateOrganizationInvitationParams,
4-
MembershipRole,
4+
OrganizationCustomRoleKey,
55
OrganizationInvitationJSON,
66
OrganizationInvitationResource,
77
OrganizationInvitationStatus,
@@ -16,7 +16,7 @@ export class OrganizationInvitation extends BaseResource implements Organization
1616
organizationId!: string;
1717
publicMetadata: OrganizationInvitationPublicMetadata = {};
1818
status!: OrganizationInvitationStatus;
19-
role!: MembershipRole;
19+
role!: OrganizationCustomRoleKey;
2020
createdAt!: Date;
2121
updatedAt!: Date;
2222

‎packages/clerk-js/src/core/resources/OrganizationMembership.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
ClerkPaginatedResponse,
33
ClerkResourceReloadParams,
44
GetUserOrganizationMembershipParams,
5-
MembershipRole,
5+
OrganizationCustomRoleKey,
66
OrganizationMembershipJSON,
77
OrganizationMembershipResource,
88
OrganizationPermissionKey,
@@ -18,7 +18,7 @@ export class OrganizationMembership extends BaseResource implements Organization
1818
publicUserData!: PublicUserData;
1919
organization!: Organization;
2020
permissions: OrganizationPermissionKey[] = [];
21-
role!: MembershipRole;
21+
role!: OrganizationCustomRoleKey;
2222
createdAt!: Date;
2323
updatedAt!: Date;
2424

@@ -117,7 +117,7 @@ export class OrganizationMembership extends BaseResource implements Organization
117117
}
118118

119119
export type UpdateOrganizationMembershipParams = {
120-
role: MembershipRole;
120+
role: OrganizationCustomRoleKey;
121121
};
122122

123123
export type GetOrganizationMembershipsClass = (

‎packages/clerk-js/src/core/resources/UserOrganizationInvitation.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {
22
ClerkPaginatedResponse,
33
GetUserOrganizationInvitationsParams,
4-
MembershipRole,
4+
OrganizationCustomRoleKey,
55
OrganizationInvitationStatus,
66
UserOrganizationInvitationJSON,
77
UserOrganizationInvitationResource,
@@ -17,7 +17,7 @@ export class UserOrganizationInvitation extends BaseResource implements UserOrga
1717
publicOrganizationData!: UserOrganizationInvitationResource['publicOrganizationData'];
1818
publicMetadata: OrganizationInvitationPublicMetadata = {};
1919
status!: OrganizationInvitationStatus;
20-
role!: MembershipRole;
20+
role!: OrganizationCustomRoleKey;
2121
createdAt!: Date;
2222
updatedAt!: Date;
2323

‎packages/clerk-js/src/ui/common/Gate.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useSession } from '@clerk/shared/react';
2-
import type { CheckAuthorization, MembershipRole, OrganizationPermissionKey } from '@clerk/types';
2+
import type { CheckAuthorization, OrganizationCustomRoleKey, OrganizationPermissionKey } from '@clerk/types';
33
import type { ComponentType, PropsWithChildren, ReactNode } from 'react';
44
import React, { useEffect } from 'react';
55

@@ -10,7 +10,7 @@ type GateProps = PropsWithChildren<
1010
(
1111
| {
1212
condition?: never;
13-
role: MembershipRole;
13+
role: OrganizationCustomRoleKey;
1414
permission?: never;
1515
}
1616
| {

‎packages/clerk-js/src/ui/components/OrganizationProfile/InviteMembersForm.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isClerkAPIResponseError } from '@clerk/shared/error';
22
import { useOrganization } from '@clerk/shared/react';
3-
import type { ClerkAPIError, MembershipRole } from '@clerk/types';
3+
import type { ClerkAPIError } from '@clerk/types';
44
import type { FormEvent } from 'react';
55
import { useState } from 'react';
66

@@ -74,7 +74,7 @@ export const InviteMembersForm = (props: InviteMembersFormProps) => {
7474
return organization
7575
.inviteMembers({
7676
emailAddresses: emailAddressField.value.split(','),
77-
role: submittedData.get('role') as MembershipRole,
77+
role: submittedData.get('role') as string,
7878
})
7979
.then(async () => {
8080
await invitations?.revalidate?.();

‎packages/clerk-js/src/ui/components/OrganizationProfile/MemberListTable.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { MembershipRole } from '@clerk/types';
21
import React, { useMemo } from 'react';
32

43
import type { LocalizationKey } from '../../customizables';
@@ -121,7 +120,7 @@ export const RowContainer = (props: PropsOfComponent<typeof Tr>) => {
121120

122121
export const RoleSelect = (props: {
123122
roles: { label: string; value: string }[] | undefined;
124-
value: MembershipRole;
123+
value: string;
125124
onChange: (params: string) => unknown;
126125
isDisabled?: boolean;
127126
triggerSx?: ThemableCssProp;

‎packages/clerk-js/src/ui/utils/roleLocalizationKey.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
import type { MembershipRole } from '@clerk/types';
2-
31
import type { LocalizationKey } from '../localization/localizationKeys';
42
import { localizationKeys } from '../localization/localizationKeys';
53

6-
const roleToLocalizationKey: Record<MembershipRole, LocalizationKey> = {
4+
const roleToLocalizationKey: Record<string, LocalizationKey> = {
5+
/**
6+
* These are old role keys. We still need to support localization for those to avoid breaking labels in UI components for old instances.
7+
*/
78
basic_member: localizationKeys('membershipRole__basicMember'),
89
guest_member: localizationKeys('membershipRole__guestMember'),
910
admin: localizationKeys('membershipRole__admin'),
1011
};
1112

12-
export const roleLocalizationKey = (role: MembershipRole | undefined): LocalizationKey | undefined => {
13+
export const roleLocalizationKey = (role: string | undefined): LocalizationKey | undefined => {
1314
if (!role) {
1415
return undefined;
1516
}
1617
return roleToLocalizationKey[role];
1718
};
1819

19-
export const customRoleLocalizationKey = (role: MembershipRole | undefined): LocalizationKey | undefined => {
20+
export const customRoleLocalizationKey = (role: string | undefined): LocalizationKey | undefined => {
2021
if (!role) {
2122
return undefined;
2223
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
ActJWTClaim,
33
CheckAuthorizationWithCustomPermissions,
44
GetToken,
5-
MembershipRole,
5+
OrganizationCustomRoleKey,
66
SignOut,
77
} from '@clerk/types';
88
import { useCallback } from 'react';
@@ -64,7 +64,7 @@ type UseAuthReturn =
6464
sessionId: string;
6565
actor: ActJWTClaim | null;
6666
orgId: string;
67-
orgRole: MembershipRole;
67+
orgRole: OrganizationCustomRoleKey;
6868
orgSlug: string | null;
6969
has: CheckAuthorizationWithCustomPermissions;
7070
signOut: SignOut;

‎packages/types/src/clerk.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { DisplayThemeJSON } from './json';
1515
import type { LocalizationResource } from './localization';
1616
import type { OAuthProvider, OAuthScope } from './oauth';
1717
import type { OrganizationResource } from './organization';
18-
import type { MembershipRole } from './organizationMembership';
18+
import type { OrganizationCustomRoleKey } from './organizationMembership';
1919
import type { ActiveSessionResource } from './session';
2020
import type { UserResource } from './user';
2121
import type { Autocomplete, DeepPartial, DeepSnakeToCamel } from './utils';
@@ -935,12 +935,12 @@ export interface HandleEmailLinkVerificationParams {
935935

936936
export type CreateOrganizationInvitationParams = {
937937
emailAddress: string;
938-
role: MembershipRole;
938+
role: OrganizationCustomRoleKey;
939939
};
940940

941941
export type CreateBulkOrganizationInvitationParams = {
942942
emailAddresses: string[];
943-
role: MembershipRole;
943+
role: OrganizationCustomRoleKey;
944944
};
945945

946946
export interface CreateOrganizationParams {

‎packages/types/src/json.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { ActJWTClaim } from './jwt';
77
import type { OAuthProvider } from './oauth';
88
import type { OrganizationDomainVerificationStatus, OrganizationEnrollmentMode } from './organizationDomain';
99
import type { OrganizationInvitationStatus } from './organizationInvitation';
10-
import type { MembershipRole, OrganizationPermissionKey } from './organizationMembership';
10+
import type { OrganizationCustomRoleKey, OrganizationPermissionKey } from './organizationMembership';
1111
import type { OrganizationSettingsJSON } from './organizationSettings';
1212
import type { OrganizationSuggestionStatus } from './organizationSuggestion';
1313
import type { SamlIdpSlug } from './saml';
@@ -303,7 +303,7 @@ export interface OrganizationMembershipJSON extends ClerkResourceJSON {
303303
permissions: OrganizationPermissionKey[];
304304
public_metadata: OrganizationMembershipPublicMetadata;
305305
public_user_data: PublicUserDataJSON;
306-
role: MembershipRole;
306+
role: OrganizationCustomRoleKey;
307307
created_at: number;
308308
updated_at: number;
309309
}
@@ -315,7 +315,7 @@ export interface OrganizationInvitationJSON extends ClerkResourceJSON {
315315
organization_id: string;
316316
public_metadata: OrganizationInvitationPublicMetadata;
317317
status: OrganizationInvitationStatus;
318-
role: MembershipRole;
318+
role: OrganizationCustomRoleKey;
319319
created_at: number;
320320
updated_at: number;
321321
}
@@ -403,7 +403,7 @@ export interface UserOrganizationInvitationJSON extends ClerkResourceJSON {
403403
public_organization_data: PublicOrganizationDataJSON;
404404
public_metadata: OrganizationInvitationPublicMetadata;
405405
status: OrganizationInvitationStatus;
406-
role: MembershipRole;
406+
role: OrganizationCustomRoleKey;
407407
created_at: number;
408408
updated_at: number;
409409
}

‎packages/types/src/jwt.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MembershipRole } from './organizationMembership';
1+
import type { OrganizationCustomRoleKey } from './organizationMembership';
22

33
export interface JWT {
44
encoded: { header: string; payload: string; signature: string };
@@ -84,7 +84,7 @@ export interface ClerkJWTClaims {
8484
/**
8585
* Active organization role
8686
*/
87-
org_role?: MembershipRole;
87+
org_role?: OrganizationCustomRoleKey;
8888

8989
/**
9090
* Any other JWT Claim Set member.
@@ -100,4 +100,4 @@ export interface ActJWTClaim {
100100
[x: string]: unknown;
101101
}
102102

103-
export type OrganizationsJWTClaim = Record<string, MembershipRole>;
103+
export type OrganizationsJWTClaim = Record<string, OrganizationCustomRoleKey>;

‎packages/types/src/jwtv2.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MembershipRole, OrganizationCustomPermissionKey } from './organizationMembership';
1+
import type { OrganizationCustomPermissionKey, OrganizationCustomRoleKey } from './organizationMembership';
22

33
export interface Jwt {
44
header: JwtHeader;
@@ -94,7 +94,7 @@ export interface JwtPayload extends CustomJwtSessionClaims {
9494
/**
9595
* Active organization role
9696
*/
97-
org_role?: MembershipRole;
97+
org_role?: OrganizationCustomRoleKey;
9898

9999
/**
100100
* Active organization role

‎packages/types/src/organization.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { OrganizationDomainResource, OrganizationEnrollmentMode } from './organizationDomain';
22
import type { OrganizationInvitationResource, OrganizationInvitationStatus } from './organizationInvitation';
3-
import type { MembershipRole, OrganizationMembershipResource } from './organizationMembership';
3+
import type { OrganizationCustomRoleKey, OrganizationMembershipResource } from './organizationMembership';
44
import type { OrganizationMembershipRequestResource } from './organizationMembershipRequest';
55
import type { ClerkPaginatedResponse, ClerkPaginationParams } from './pagination';
66
import type { ClerkResource } from './resource';
@@ -67,7 +67,7 @@ export interface OrganizationResource extends ClerkResource {
6767
export type GetRolesParams = ClerkPaginationParams;
6868

6969
export type GetMembersParams = ClerkPaginationParams<{
70-
role?: MembershipRole[];
70+
role?: OrganizationCustomRoleKey[];
7171
}>;
7272

7373
export type GetDomainsParams = ClerkPaginationParams<{
@@ -84,22 +84,22 @@ export type GetMembershipRequestParams = ClerkPaginationParams<{
8484

8585
export interface AddMemberParams {
8686
userId: string;
87-
role: MembershipRole;
87+
role: OrganizationCustomRoleKey;
8888
}
8989

9090
export interface InviteMemberParams {
9191
emailAddress: string;
92-
role: MembershipRole;
92+
role: OrganizationCustomRoleKey;
9393
}
9494

9595
export interface InviteMembersParams {
9696
emailAddresses: string[];
97-
role: MembershipRole;
97+
role: OrganizationCustomRoleKey;
9898
}
9999

100100
export interface UpdateMembershipParams {
101101
userId: string;
102-
role: MembershipRole;
102+
role: OrganizationCustomRoleKey;
103103
}
104104

105105
export interface UpdateOrganizationParams {

‎packages/types/src/organizationInvitation.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MembershipRole } from './organizationMembership';
1+
import type { OrganizationCustomRoleKey } from './organizationMembership';
22
import type { ClerkResource } from './resource';
33

44
declare global {
@@ -21,7 +21,7 @@ export interface OrganizationInvitationResource extends ClerkResource {
2121
emailAddress: string;
2222
organizationId: string;
2323
publicMetadata: OrganizationInvitationPublicMetadata;
24-
role: MembershipRole;
24+
role: OrganizationCustomRoleKey;
2525
status: OrganizationInvitationStatus;
2626
createdAt: Date;
2727
updatedAt: Date;

‎packages/types/src/organizationMembership.ts

+5-14
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface OrganizationMembershipResource extends ClerkResource {
4343
permissions: OrganizationPermissionKey[];
4444
publicMetadata: OrganizationMembershipPublicMetadata;
4545
publicUserData: PublicUserData;
46-
role: MembershipRole;
46+
role: OrganizationCustomRoleKey;
4747
createdAt: Date;
4848
updatedAt: Date;
4949
destroy: () => Promise<OrganizationMembershipResource>;
@@ -56,24 +56,15 @@ export type OrganizationCustomPermissionKey = ClerkAuthorization extends Placeho
5656
: Base['permission']
5757
: Base['permission'];
5858

59+
/**
60+
* OrganizationCustomRoleKey will be string unless the developer has provided their own types through `ClerkAuthorization`
61+
*/
5962
export type OrganizationCustomRoleKey = ClerkAuthorization extends Placeholder
6063
? ClerkAuthorization['role'] extends string
6164
? ClerkAuthorization['role']
6265
: Base['role']
6366
: Base['role'];
6467

65-
/**
66-
* @deprecated This type is deprecated and will be removed in the next major release.
67-
* Use `OrganizationCustomRoleKey` instead.
68-
* MembershipRole includes `admin`, `basic_member`, `guest_member`. With the introduction of "Custom roles"
69-
* these types will no longer match a developer's custom logic.
70-
*/
71-
export type MembershipRole = ClerkAuthorization extends Placeholder
72-
? ClerkAuthorization['role'] extends string
73-
? ClerkAuthorization['role'] | 'admin' | 'basic_member' | 'guest_member'
74-
: Autocomplete<'admin' | 'basic_member' | 'guest_member'>
75-
: Autocomplete<'admin' | 'basic_member' | 'guest_member'>;
76-
7768
export type OrganizationSystemPermissionKey =
7869
| 'org:sys_domains:manage'
7970
| 'org:sys_profile:manage'
@@ -93,5 +84,5 @@ export type OrganizationPermissionKey = ClerkAuthorization extends Placeholder
9384
: Autocomplete<OrganizationSystemPermissionKey>;
9485

9586
export type UpdateOrganizationMembershipParams = {
96-
role: MembershipRole;
87+
role: OrganizationCustomRoleKey;
9788
};

‎packages/types/src/session.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { ActJWTClaim } from './jwt';
22
import type {
3-
MembershipRole,
43
OrganizationCustomPermissionKey,
54
OrganizationCustomRoleKey,
65
OrganizationPermissionKey,
@@ -28,7 +27,7 @@ export type CheckAuthorization = CheckAuthorizationFn<CheckAuthorizationParams>;
2827

2928
type CheckAuthorizationParams =
3029
| {
31-
role: MembershipRole;
30+
role: OrganizationCustomRoleKey;
3231
permission?: never;
3332
}
3433
| {

‎packages/types/src/ssr.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ActClaim, JwtPayload } from './jwtv2';
22
import type { OrganizationResource } from './organization';
3-
import type { MembershipRole, OrganizationCustomPermissionKey } from './organizationMembership';
3+
import type { OrganizationCustomPermissionKey, OrganizationCustomRoleKey } from './organizationMembership';
44
import type { SessionResource } from './session';
55
import type { UserResource } from './user';
66
import type { Serializable } from './utils';
@@ -16,7 +16,7 @@ export type InitialState = Serializable<{
1616
userId: string | undefined;
1717
user: UserResource | undefined;
1818
orgId: string | undefined;
19-
orgRole: MembershipRole | undefined;
19+
orgRole: OrganizationCustomRoleKey | undefined;
2020
orgSlug: string | undefined;
2121
orgPermissions: OrganizationCustomPermissionKey[] | undefined;
2222
organization: OrganizationResource | undefined;

‎packages/types/src/userOrganizationInvitation.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { OrganizationInvitationStatus } from './organizationInvitation';
2-
import type { MembershipRole } from './organizationMembership';
2+
import type { OrganizationCustomRoleKey } from './organizationMembership';
33
import type { ClerkResource } from './resource';
44

55
declare global {
@@ -28,7 +28,7 @@ export interface UserOrganizationInvitationResource extends ClerkResource {
2828
slug: string | null;
2929
};
3030
publicMetadata: UserOrganizationInvitationPublicMetadata;
31-
role: MembershipRole;
31+
role: OrganizationCustomRoleKey;
3232
status: OrganizationInvitationStatus;
3333
createdAt: Date;
3434
updatedAt: Date;

0 commit comments

Comments
 (0)
Please sign in to comment.