Skip to content

Commit cc996cd

Browse files
yoland68DrJKL
authored andcommitted
[feat] Add account deletion functionality to UserPanel component
- Implemented a new button for deleting user accounts in UserPanel.vue - Added confirmation dialog for account deletion using dialogService - Integrated deleteAccount action in useFirebaseAuthActions - Updated en files to include new translation keys for account deletion
1 parent 9e8db61 commit cc996cd

File tree

5 files changed

+69
-10
lines changed

5 files changed

+69
-10
lines changed

src/components/dialog/content/setting/UserPanel.vue

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,23 @@
5757
class="w-8 h-8 mt-4"
5858
style="--pc-spinner-color: #000"
5959
/>
60-
<Button
61-
v-else
62-
class="mt-4 w-32"
63-
severity="secondary"
64-
:label="$t('auth.signOut.signOut')"
65-
icon="pi pi-sign-out"
66-
@click="handleSignOut"
67-
/>
60+
<div v-else class="mt-4 flex flex-col gap-2">
61+
<Button
62+
class="w-32"
63+
severity="secondary"
64+
:label="$t('auth.signOut.signOut')"
65+
icon="pi pi-sign-out"
66+
@click="handleSignOut"
67+
/>
68+
<Button
69+
v-if="!isApiKeyLogin"
70+
class="w-32"
71+
severity="danger"
72+
:label="$t('auth.deleteAccount.deleteAccount')"
73+
icon="pi pi-trash"
74+
@click="handleDeleteAccount"
75+
/>
76+
</div>
6877
</div>
6978

7079
<!-- Login Section -->
@@ -100,13 +109,15 @@ const dialogService = useDialogService()
100109
const {
101110
loading,
102111
isLoggedIn,
112+
isApiKeyLogin,
103113
isEmailProvider,
104114
userDisplayName,
105115
userEmail,
106116
userPhotoUrl,
107117
providerName,
108118
providerIcon,
109119
handleSignOut,
110-
handleSignIn
120+
handleSignIn,
121+
handleDeleteAccount
111122
} = useCurrentUser()
112123
</script>

src/composables/auth/useCurrentUser.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { computed } from 'vue'
22

3+
import { useFirebaseAuthActions } from '@/composables/auth/useFirebaseAuthActions'
4+
import { t } from '@/i18n'
5+
import { useDialogService } from '@/services/dialogService'
36
import { useApiKeyAuthStore } from '@/stores/apiKeyAuthStore'
47
import { useCommandStore } from '@/stores/commandStore'
58
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
@@ -8,6 +11,8 @@ export const useCurrentUser = () => {
811
const authStore = useFirebaseAuthStore()
912
const commandStore = useCommandStore()
1013
const apiKeyStore = useApiKeyAuthStore()
14+
const dialogService = useDialogService()
15+
const { deleteAccount } = useFirebaseAuthActions()
1116

1217
const firebaseUser = computed(() => authStore.currentUser)
1318
const isApiKeyLogin = computed(() => apiKeyStore.isAuthenticated)
@@ -85,6 +90,18 @@ export const useCurrentUser = () => {
8590
await commandStore.execute('Comfy.User.OpenSignInDialog')
8691
}
8792

93+
const handleDeleteAccount = async () => {
94+
const confirmed = await dialogService.confirm({
95+
title: t('auth.deleteAccount.confirmTitle'),
96+
message: t('auth.deleteAccount.confirmMessage'),
97+
type: 'delete'
98+
})
99+
100+
if (confirmed) {
101+
await deleteAccount()
102+
}
103+
}
104+
88105
return {
89106
loading: authStore.loading,
90107
isLoggedIn,
@@ -96,6 +113,7 @@ export const useCurrentUser = () => {
96113
providerName,
97114
providerIcon,
98115
handleSignOut,
99-
handleSignIn
116+
handleSignIn,
117+
handleDeleteAccount
100118
}
101119
}

src/composables/auth/useFirebaseAuthActions.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ export const useFirebaseAuthActions = () => {
135135
reportError
136136
)
137137

138+
const deleteAccount = wrapWithErrorHandlingAsync(async () => {
139+
await authStore.deleteAccount()
140+
toastStore.add({
141+
severity: 'success',
142+
summary: t('auth.deleteAccount.success'),
143+
detail: t('auth.deleteAccount.successDetail'),
144+
life: 5000
145+
})
146+
}, reportError)
147+
138148
return {
139149
logout,
140150
sendPasswordReset,
@@ -146,6 +156,7 @@ export const useFirebaseAuthActions = () => {
146156
signInWithEmail,
147157
signUpWithEmail,
148158
updatePassword,
159+
deleteAccount,
149160
accessError
150161
}
151162
}

src/locales/en/main.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,15 @@
16011601
"passwordUpdate": {
16021602
"success": "Password Updated",
16031603
"successDetail": "Your password has been updated successfully"
1604+
},
1605+
"deleteAccount": {
1606+
"deleteAccount": "Delete Account",
1607+
"confirmTitle": "Delete Account",
1608+
"confirmMessage": "Are you sure you want to delete your account? This action cannot be undone and will permanently remove all your data.",
1609+
"confirm": "Delete Account",
1610+
"cancel": "Cancel",
1611+
"success": "Account Deleted",
1612+
"successDetail": "Your account has been successfully deleted."
16041613
}
16051614
},
16061615
"validation": {

src/stores/firebaseAuthStore.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type UserCredential,
99
browserLocalPersistence,
1010
createUserWithEmailAndPassword,
11+
deleteUser,
1112
onAuthStateChanged,
1213
sendPasswordResetEmail,
1314
setPersistence,
@@ -287,6 +288,14 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
287288
await updatePassword(currentUser.value, newPassword)
288289
}
289290

291+
/** Delete the current user account */
292+
const _deleteAccount = async (): Promise<void> => {
293+
if (!currentUser.value) {
294+
throw new FirebaseAuthStoreError(t('toastMessages.userNotAuthenticated'))
295+
}
296+
await deleteUser(currentUser.value)
297+
}
298+
290299
const addCredits = async (
291300
requestBodyContent: CreditPurchasePayload
292301
): Promise<CreditPurchaseResponse> => {
@@ -385,6 +394,7 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
385394
accessBillingPortal,
386395
sendPasswordReset,
387396
updatePassword: _updatePassword,
397+
deleteAccount: _deleteAccount,
388398
getAuthHeader
389399
}
390400
})

0 commit comments

Comments
 (0)