简体   繁体   English

Firebase 身份验证密码重置

[英]Firebase auth password reset

I'm working on a firebase app that contains an authentication system that allows users to sign up/login and create a profile.我正在开发一个包含身份验证系统的 firebase 应用程序,该系统允许用户注册/登录并创建配置文件。 The app stores and calls profile info about the users.该应用程序存储和调用有关用户的个人资料信息。 The system worked just fine until I realized there's no way for a user to reset their password.系统工作得很好,直到我意识到用户无法重置密码。 So I added sendPasswordResetEmail function and it's been downhill since then.所以我添加了 sendPasswordResetEmail 功能,从那以后它一直在走下坡路。 I'm a newbie to firebase and to StackOverflow so forgive the mess you're about to see.我是 firebase 和 StackOverflow 的新手,所以请原谅你即将看到的混乱。 Am I missing something in that function?我在那个功能中遗漏了什么吗?

const resetpassword = async () => {
const email = document.getElementById('email').value;
  try {
   const { user } = auth.sendPasswordResetEmail(email);
    alert('Password Reset Email Sent!');
    }
    catch(error) {
     console.log("error ===>", error);    
    if (error.message === "Firebase: Error (auth/user-not-found).") {
        alert("There is no user corresponding to this email address.")}
    else (errorCode == 'auth/invalid-email') {
      alert(errorMessage)} 
    }
 }

If you are using firebase version 9 then use code snippet below to reset user password如果您使用的是 firebase 版本 9,请使用下面的代码片段重置用户密码

 import { getAuth, sendPasswordResetEmail } from "firebase/auth"; const auth = getAuth(); sendPasswordResetEmail(auth, email) .then(() => { // Password reset email sent! // .. }) .catch((error) => { const errorCode = error.code; const errorMessage = error.message; // .. });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM