Skip to content

Commit

Permalink
feat(clerk-js): Hide 'create organization' button in org switcher if …
Browse files Browse the repository at this point in the history
…no permissions
  • Loading branch information
jescalan committed Jun 16, 2023
1 parent e344851 commit 3c2c4e3
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/clerk-js/src/core/resources/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class User extends BaseResource implements UserResource {
publicMetadata: UserPublicMetadata = {};
unsafeMetadata: UserUnsafeMetadata = {};
lastSignInAt: Date | null = null;
createOrganizationEnabled = false;
updatedAt: Date | null = null;
createdAt: Date | null = null;

Expand Down Expand Up @@ -320,7 +321,6 @@ export class User extends BaseResource implements UserResource {
this.twoFactorEnabled = data.two_factor_enabled;

this.createOrganizationEnabled = data.create_organization_enabled;
this.deleteSelfEnabled = data.delete_self_enabled;

if (data.last_sign_in_at) {
this.lastSignInAt = unixEpochToDate(data.last_sign_in_at);
Expand Down
4 changes: 4 additions & 0 deletions packages/clerk-js/src/core/resources/UserSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { BaseResource } from './internal';
const defaultMaxPasswordLength = 72;
const defaultMinPasswordLength = 8;

export type Actions = {
create_organization: boolean;
};

/**
* @internal
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const OrganizationActionList = (props: OrganizationActionListProps) => {
</PreviewButton>
))}
</Box>
{createOrganizationButton}
{user.createOrganizationEnabled && createOrganizationButton}
</SecondaryActions>
);
};
1 change: 1 addition & 0 deletions packages/types/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export interface UserJSON extends ClerkResourceJSON {
public_metadata: UserPublicMetadata;
unsafe_metadata: UserUnsafeMetadata;
last_sign_in_at: number | null;
create_organization_enabled: boolean;
updated_at: number;
created_at: number;
}
Expand Down
1 change: 0 additions & 1 deletion packages/types/src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export interface UserResource extends ClerkResource {
unsafeMetadata: UserUnsafeMetadata;
lastSignInAt: Date | null;
createOrganizationEnabled: boolean;
deleteSelfEnabled: boolean;
updatedAt: Date | null;
createdAt: Date | null;

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/userSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ export type Attributes = {
};

export type Actions = {
delete_self: boolean;
create_organization: boolean;
};

export interface UserSettingsJSON extends ClerkResourceJSON {
id: never;
object: never;
attributes: AttributesJSON;
actions: Actions;
social: OAuthProviders;

/**
Expand Down

0 comments on commit 3c2c4e3

Please sign in to comment.