5

से उपयोगकर्ता को हटाने में असमर्थ मैं अपने वर्तमान उपयोगकर्ता को फायरबेस से हटाना चाहता हूं। प्रमाणीकृत उपयोगकर्ता हटा दिया जाता है, हालांकि, मैं डेटाबेस में उस उपयोगकर्ता के डेटा को हटाने में असमर्थ हूं। मैं क्या गलत कर रहा हूं?आईओएस स्विफ्ट: फ़ायरबेस डाटाबेस

यह मेरा हटाने उपयोगकर्ता विधि ....

FIRAuth.auth()?.signIn(withEmail: (emailTextField?.text)! , password: (passwordTextField?.text)!, completion: { (user, error) in 
      if error == nil { 
       print("User Authenticate!!!") 
       let user = FIRAuth.auth()?.currentUser 

       user?.delete(completion: { (error) in 
        if error != nil { 
         print("Error unable to delete user") 

        } else { 

         DataService.ds.deleteCurrentFirebaseDBUser() 
         KeychainWrapper.standard.removeObject(forKey: KEY_UID) 
         self.performSegue(withIdentifier: "goToLogin", sender: nil) 
        } 
       }) 

      } else { 
       //Password was wrong, unable to authenicate user. Data is not updated 
       print("!!!ALERT!!! Unable to authenticate user") 
       let alert = UIAlertController(title: "Incorrect Password", message: "Please re-enter your password", preferredStyle: UIAlertControllerStyle.alert) 
       alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) 
       self.present(alert, animated: true, completion: nil) 
      } 

     }) 

Firebase नियम है:

{ 
"rules": { 
    "users": { 
     "$uid": { 
     ".read": "$uid === auth.uid", 
     ".write": "$uid === auth.uid" 
     } 
    } 
    } 
} 

डेटाबेस:

App 
    -> users 
      -> 
      4erkjkl543jfe46 
          ->name 
          ->email 

त्रुटियों:

2017-01- 21 21: 33: 10.321704 एपीपी [11582: 4102711] [फ़िर ebaseDatabase] setValue: या removeValue: उन पर// 4erkjkl543jfe46 विफल रहा: permission_denied

वैकल्पिक (त्रुटि डोमेन = com.firebase कोड = 1 "अनुमति अस्वीकृत" UserInfo = {NSLocalizedDescription = अनुमति अस्वीकृत})

उत्तर

3

मैं एक ही मुद्दा है। आप अपने फ़ंक्शन को का उपयोग करने में सक्षम नहीं हैं CurrentFirebaseDBUser() क्योंकि फ़ायरबेस डिलीट फ़ंक्शन (यदि सफल हो) उपयोगकर्ता ऑथ ऑब्जेक्ट को हटा देता है, जिसके परिणामस्वरूप उपयोगकर्ता को प्रमाणीकृत नहीं किया जाता है जब आप deleteCurrentFirebaseDBUser के साथ डेटाबेस में उपयोगकर्ता के डेटा को हटाना चाहते हैं ()। वर्तमान में मैं फ़ायरबेस डिलीट फ़ंक्शन से पहले डेटाबेस में उपयोगकर्ता का डेटा हटा देता हूं जो आदर्श समाधान नहीं है।

+0

भावना बनाता है:

यहाँ सुंदर कोड है। बहुत बढ़िया!! धन्यवाद, यह काम करता है। – Nick

0

हम दोनों तरफ प्रमाणीकरण और डेटाबेस से उपयोगकर्ता हटा सकते हैं। लेकिन इससे पहले हमें पहले उपयोगकर्ता को पुनः प्रमाणित करने की आवश्यकता है तो हमें उपयोगकर्ता को हटाने के लिए नवीनतम टोकन मिलता है।

let user = Auth.auth().currentUser 
      user?.reauthenticate(with:credential) { error in 
       if let error = error { 
        // An error happened. 
        showAlertWithErrorMessage(message: error.localizedDescription) 
       } else { 
        // User re-authenticated. 
        user?.delete { error in 
         if let error = error { 
          // An error happened. 
          showAlertWithErrorMessage(message: error.localizedDescription) 
         } else { 
          // Account deleted. 
          let userID = HelperFunction.helper.FetchFromUserDefault(name: kUID) 
          Database.database().reference(fromURL: kFirebaseLink).child(kUser).child(userID).removeValue() 

          try! Auth.auth().signOut() 
          showAlertWithErrorMessage(message: "Your account deleted successfully...") 
          return 
         } 
        } 

       } 
      } 

100% अपने प्रोजेक्ट में काम कर रहे हैं और अच्छी तरह से परीक्षण किया

संबंधित मुद्दे