Firebase User re-authentication initialising error

ⅰ亾dé卋堺 提交于 2019-12-06 14:48:27

问题


When any user wants to update his/her password from app, i want to update that password of same FCM user and for that i have tried below code which define in official doc.

here is the screenshot of that

Here is my code

func authenticateAndUpdateFCMUserPassword(strNewPassword: String) {
    let user = Auth.auth().currentUser
    var credential: AuthCredential

    // Prompt the user to re-provide their sign-in credentials
    user?.reauthenticate(with: credential) { error in
        if let error = error {
            // An error happened.
        } else {
            // User re-authenticated.
        }
    }

    Auth.auth().currentUser?.updatePassword(to: strNewPassword) { (error) in
        if error != nil {
            print("Error occur while updating password")
        }
        else {
            print("Password Updated Successfully")
        }
    }
}

But in above code i'm facing below error at user?.reauthenticate line

Cannot convert value of type '(_) -> ()' to expected argument type 'AuthDataResultCallback?' (aka 'Optional<(Optional, Optional) -> ()>')

so i re write that by below code

user?.reauthenticate(with: credential, completion: { (dataResult, errorr) in
    if errorr != nil {
        // An error happened.
    } else {
        // User re-authenticated.
    }
})

but in above code i'm facing below error

Variable 'credential' used before being initialized

credential is defined only once and never used before this

will anyone please let me know what i'm doing wrong?

来源:https://stackoverflow.com/questions/57704646/firebase-user-re-authentication-initialising-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!