Updated approach to Reauthenticate a user

后端 未结 1 1087
刺人心
刺人心 2021-01-20 19:57

I\'ve been looking in the Firebase Documentation and found the method to reauthenticate a user shown below.

let user = Auth.auth().currentUser
var credential         


        
1条回答
  •  情话喂你
    2021-01-20 20:58

    let user = Auth.auth().currentUser
    var credential: AuthCredential
    user?.reauthenticateAndRetrieveData(with: credential, completion: {(authResult, error) in
                if let error = error {
                    // An error happened.
                }else{
                    // User re-authenticated.
                }
            })
    

    You are getting error because you haven't initialize credential You have to initialize AuthCredential first

    These credential can vary from

    EmailAuthCredential

    FacebookAuthCredential

    GithubAuthCredential

    GoogleAuthCredential

    PhoneAuthCredential

    PlayGamesAuthCredential

    TwitterAuthCredential

    Initiziale the variable according to your authentication method e.g. if you have chosen email you can use like

    var credential: AuthCredential = EmailAuthProvider.credential(withEmail: "email", password: "pass")
    

    0 讨论(0)
提交回复
热议问题