Skip to content

Commit

Permalink
User delete self fixes (#1372)
Browse files Browse the repository at this point in the history
* fix(clerk-js): Fix data sourcing for delete user feature
  • Loading branch information
jescalan committed Jun 19, 2023
1 parent 6041b8e commit 3214849
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/silver-cheetahs-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
'@clerk/types': patch
---

Fix to pull from the correct permissions set when displaying user delete self UI
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;
deleteSelfEnabled = false;
updatedAt: Date | null = null;
createdAt: Date | null = null;

Expand Down Expand Up @@ -319,6 +320,8 @@ export class User extends BaseResource implements UserResource {
this.backupCodeEnabled = data.backup_code_enabled;
this.twoFactorEnabled = data.two_factor_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: 2 additions & 2 deletions packages/clerk-js/src/ui/components/UserProfile/RootPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Web3Section } from './Web3Section';
import { DeleteSection } from './DeleteSection';

export const RootPage = withCardStateProvider(() => {
const { attributes, saml, social, actions, instanceIsPasswordBased } = useEnvironment().userSettings;
const { attributes, saml, social, instanceIsPasswordBased } = useEnvironment().userSettings;
const card = useCardState();
const user = useCoreUser();
const showUsername = attributes.username.enabled;
Expand All @@ -27,7 +27,7 @@ export const RootPage = withCardStateProvider(() => {
const showWeb3 = attributes.web3_wallet.enabled;
const showPassword = instanceIsPasswordBased;
const showMfa = getSecondFactors(attributes).length > 0;
const showDelete = actions.delete_self;
const showDelete = user.deleteSelfEnabled;

return (
<Col
Expand Down
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;
delete_self_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;
deleteSelfEnabled: boolean;
updatedAt: Date | null;
createdAt: Date | null;

Expand Down

0 comments on commit 3214849

Please sign in to comment.