Skip to content

Commit

Permalink
feat:#683 - delete user issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sana7044 committed Jan 1, 2025
1 parent 5857a37 commit b3afc73
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions src/stores/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import {
GoogleAuthProvider,
signInWithEmailAndPassword,
signInWithPopup,
signOut
signOut,
getAuth,
deleteUser as authDeleteUser
} from 'firebase/auth'
import { collection, doc, getDoc, getDocs, onSnapshot, or, query, runTransaction, setDoc, where } from 'firebase/firestore'
import { collection, doc, deleteDoc, getDoc, getDocs, onSnapshot, or, query, runTransaction, setDoc, where } from 'firebase/firestore'
import { defineStore } from 'pinia'
import { LocalStorage, Notify } from 'quasar'
import sha1 from 'sha1'
import { auth, db } from 'src/firebase'
import { baseURL } from 'stores/stats'
import { mock_layer8_interceptor } from 'mock_layer8_module'
import { useWalletStore } from 'stores/wallet'
import { deleteDoc } from 'firebase/firestore'

export const useUserStore = defineStore('user', {
state: () => ({
Expand Down Expand Up @@ -230,12 +231,14 @@ export const useUserStore = defineStore('user', {
try {
await deleteDoc(doc(db, 'users', uid))

this._users = this._users.filter((user) => user.uid !== uid)
getAuth()
await authDeleteUser(uid)

Notify.create({
color: 'positive',
message: 'User deleted successfully'
})
this._users = this._users.filter((user) => user.uid !== uid)
} catch (error) {
console.error('Error deleting user: ', error)
Notify.create({
Expand All @@ -246,9 +249,47 @@ export const useUserStore = defineStore('user', {
this._isLoading = false
}
}
// async deleteUser(uid) {
// this._isLoading = true;
// try {
// // Delete from Firestore
// await deleteDoc(doc(db, 'users', uid));

// // Delete from Firebase Authentication
// const userAuth = getAuth();
// const currentUser = userAuth.currentUser;

// if (currentUser?.uid === uid) {
// // If the user to delete is the currently authenticated user
// await signOut(userAuth);
// await authDeleteUser(currentUser);
// } else {
// // For deleting other users, this requires Firebase Admin privileges
// throw new Error(
// 'Deleting a user from Firebase Authentication by UID requires Firebase Admin privileges.'
// );
// }

// Notify.create({
// color: 'positive',
// message: 'User deleted successfully',
// });

// // Remove the user from the local state
// this._users = this._users.filter((user) => user.uid !== uid);
// } catch (error) {
// console.error('Error deleting user: ', error);
// Notify.create({
// color: 'negative',
// message: 'Error deleting user. Please try again.',
// });
// } finally {
// this._isLoading = false;
// }
// }

// async addAllUsers(users) {
// await fetch(`${baseURL}/add-all-users`, {
// await fetch(${baseURL}/add-all-users, {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json'
Expand All @@ -258,7 +299,7 @@ export const useUserStore = defineStore('user', {
// },

// async getStatsUsers() {
// const allUsers = await mock_layer8_interceptor.fetch(`${baseURL}/users`, {
// const allUsers = await mock_layer8_interceptor.fetch(${baseURL}/users, {
// method: 'GET'
// })
// this._statsUsers = await allUsers.json()
Expand Down

0 comments on commit b3afc73

Please sign in to comment.