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 9651658 commit 5274f30
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions 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 @@ -315,6 +316,8 @@ export class User extends BaseResource implements UserResource {
this.backupCodeEnabled = data.backup_code_enabled;
this.twoFactorEnabled = data.two_factor_enabled;

this.createOrganizationEnabled = data.create_organization_enabled;

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

export type Actions = {
create_organization: boolean;
};

/**
* @internal
*/
Expand All @@ -29,6 +33,7 @@ export class UserSettings extends BaseResource implements UserSettingsResource {
saml!: SamlSettings;

attributes!: Attributes;
actions!: Actions;
signIn!: SignInData;
signUp!: SignUpData;
passwordSettings!: PasswordSettingsData;
Expand Down Expand Up @@ -65,6 +70,7 @@ export class UserSettings extends BaseResource implements UserSettingsResource {
this.attributes = Object.fromEntries(
Object.entries(data.attributes).map(a => [a[0], { ...a[1], name: a[0] }]),
) as Attributes;
this.actions = data.actions;
this.signIn = data.sign_in;
this.signUp = data.sign_up;
this.passwordSettings = {
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: 1 addition & 0 deletions packages/types/src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export interface UserResource extends ClerkResource {
publicMetadata: UserPublicMetadata;
unsafeMetadata: UserUnsafeMetadata;
lastSignInAt: Date | null;
createOrganizationEnabled: boolean;
updatedAt: Date | null;
createdAt: Date | null;

Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/userSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ export type Attributes = {
[attribute in Attribute]: AttributeData;
};

export type Actions = {
create_organization: boolean;
};

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

/**
Expand All @@ -108,6 +113,7 @@ export interface UserSettingsResource extends ClerkResource {
saml: SamlSettings;

attributes: Attributes;
actions: Actions;
signIn: SignInData;
signUp: SignUpData;
passwordSettings: PasswordSettingsData;
Expand Down

0 comments on commit 5274f30

Please sign in to comment.