i am using phone number authenticator for verify my user. i have verify them using following code.
PhoneAuthProvider.provider().verifyPhoneNumber(mobileNo!, uiDelegate: nil) { (verificationID, error) in
if error != nil {
self.errorLabel.text = error?.localizedDescription
}else{
log.success("\(mobileNo!)")/
// add authentication code to the defaults
let defaults = UserDefaults.standard
defaults.set(verificationID, forKey: "authVID")
self.performSegue(withIdentifier: "sendCode", sender: Any?.self)
}
}
verify the code using following code
func verifyCode(){
let defaults = UserDefaults.standard
let credential: PhoneAuthCredential = PhoneAuthProvider.provider().credential(withVerificationID: defaults.string(forKey: "authVID")!, verificationCode: verficationCodeTextField.text!)
Auth.auth().signIn(with: credential) { (user, error) in
if error != nil {
self.errorLabel.text = error?.localizedDescription
self.errorLabel.alpha = 1
}else{
self.transitionToRegistration()
}
}
}
now i need to get the userid from the authentication ?
CodePudding user response:
this can be done by using following code line.
guard let userID = Auth.auth().currentUser?.uid else { return }