Skip to content

Commit fe2607b

Browse files
authored
chore(clerk-js,types,backend): Remove MemberRole Type (clerk#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

Lines changed: 68 additions & 60 deletions

.changeset/orange-files-end.md

Lines changed: 18 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 6 additions & 5 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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 {

0 commit comments

Comments
 (0)