From 32148490b813028412af0467e342aa85227cb4d2 Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Mon, 19 Jun 2023 12:33:57 -0400 Subject: [PATCH] User delete self fixes (#1372) * fix(clerk-js): Fix data sourcing for delete user feature --- .changeset/silver-cheetahs-exercise.md | 6 ++++++ packages/clerk-js/src/core/resources/User.ts | 3 +++ .../clerk-js/src/ui/components/UserProfile/RootPage.tsx | 4 ++-- packages/types/src/json.ts | 1 + packages/types/src/user.ts | 1 + 5 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .changeset/silver-cheetahs-exercise.md diff --git a/.changeset/silver-cheetahs-exercise.md b/.changeset/silver-cheetahs-exercise.md new file mode 100644 index 0000000000..bcfcba9467 --- /dev/null +++ b/.changeset/silver-cheetahs-exercise.md @@ -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 diff --git a/packages/clerk-js/src/core/resources/User.ts b/packages/clerk-js/src/core/resources/User.ts index 771ab7f7c9..b0d7754dbd 100644 --- a/packages/clerk-js/src/core/resources/User.ts +++ b/packages/clerk-js/src/core/resources/User.ts @@ -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; @@ -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); } diff --git a/packages/clerk-js/src/ui/components/UserProfile/RootPage.tsx b/packages/clerk-js/src/ui/components/UserProfile/RootPage.tsx index 1c05e5380e..0d27fe0a0b 100644 --- a/packages/clerk-js/src/ui/components/UserProfile/RootPage.tsx +++ b/packages/clerk-js/src/ui/components/UserProfile/RootPage.tsx @@ -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; @@ -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 (