Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用react native和Firebase更改密码_Javascript_Firebase_React Native_Firebase Authentication - Fatal编程技术网

Javascript 使用react native和Firebase更改密码

Javascript 使用react native和Firebase更改密码,javascript,firebase,react-native,firebase-authentication,Javascript,Firebase,React Native,Firebase Authentication,在我们的项目中,有一个选项,用户可以更改他们的密码。这样做 在更改密码之前,用户必须输入当前密码,然后检查输入的密码是否与当前保存的密码匹配 如果可以,则用户必须用新密码更新旧密码(保存的密码) 我正在使用react native和Firebase进行项目开发。如果有人知道答案,请告诉我 除非您最近通过身份验证,否则Firebase Auth不会允许您更改密码。如果您试图updatePassword而没有经过最近的身份验证,您将得到一个错误auth/需要最近登录。 以下是您如何做到这一点: //

在我们的项目中,有一个选项,用户可以更改他们的密码。这样做

  • 在更改密码之前,用户必须输入当前密码,然后检查输入的密码是否与当前保存的密码匹配
  • 如果可以,则用户必须用新密码更新旧密码(保存的密码)
  • 我正在使用react native和Firebase进行项目开发。如果有人知道答案,请告诉我


    除非您最近通过身份验证,否则Firebase Auth不会允许您更改密码。如果您试图
    updatePassword
    而没有经过最近的身份验证,您将得到一个错误
    auth/需要最近登录
    。 以下是您如何做到这一点:

    // Ask signed in user for current password.
    const currentPass = window.prompt('Please enter current password');
    const emailCred  = firebase.auth.EmailAuthProvider.credential(
        firebase.auth().currentUser, currentPass);
    firebase.auth().currentUser.reauthenticateWithCredential(emailCred)
        .then(() => {
          // User successfully reauthenticated.
          const newPass = window.prompt('Please enter new password');
          return firebase.auth().currentUser.updatePassword(newPass);
        })
        .catch(error = > {
          // Handle error.
        });
    

    注意上面的示例,使用
    窗口。提示符
    进行说明。您可以在这里使用自己的等效react本机UI

    Firebase Auth不允许您更改密码,除非您最近通过了身份验证。如果您试图
    updatePassword
    而没有经过最近的身份验证,您将得到一个错误
    auth/需要最近登录
    。 以下是您如何做到这一点:

    // Ask signed in user for current password.
    const currentPass = window.prompt('Please enter current password');
    const emailCred  = firebase.auth.EmailAuthProvider.credential(
        firebase.auth().currentUser, currentPass);
    firebase.auth().currentUser.reauthenticateWithCredential(emailCred)
        .then(() => {
          // User successfully reauthenticated.
          const newPass = window.prompt('Please enter new password');
          return firebase.auth().currentUser.updatePassword(newPass);
        })
        .catch(error = > {
          // Handle error.
        });
    

    注意上面的示例,使用
    窗口。提示符
    进行说明。您可以在这里使用自己的等效react本机UI

    你有具体的问题吗?你应该把这个任务分解成不同的部分。如果你有一些具体的问题,回来问他们,并提供一些示例代码来解释你的问题。你有具体的问题吗?你应该把这个任务分解成不同的部分。如果您有一些特定的问题,请回来问他们,并提供一些示例代码来解释您的问题。