我知道如何更新firebase auth中用户中的密码:
var user = firebase.auth().currentUser; //get current connected user
return user.updatePassword(newPass)
.then(
() => //success
)
.catch(error => this.handleError(error))
}
但我不知道如何使用在用户中签名的。也许只有像这样的电子邮件检索用户验证持久性(但没有办法这样做):
var user = firebase.auth().getUserByEmail(email); //not implmented in auth firebase
PS:我不想使用该方法sendpasswordresetemail()
var auth = firebase.auth();
return auth.sendPasswordResetEmail(email);
非常感谢帮助, 谢谢!
如果您想要此功能,则必须自己实施。在过程结束时,您可以使用firebase admin SDK来用户配置文件中的密码。
另外,请参见:Firebase:如何使用nodejs发送密码重置电子邮件后端// ForgotPassword.js
import React, { useState } from "react";
import { sendPasswordResetEmail } from "firebase/auth";
import { Link, useNavigate } from "react-router-dom";
import { auth } from "../firebaseConfig";
const ForgotPassword = () => {
const [email, setEmail] = useState("[email protected]");
const [error, setError] = useState(null);
const [loading, setLoading] = useState(false);
const navigate = useNavigate();
const handleSubmit = async (e) => {
e.preventDefault();
setError(null);
try {
setLoading(true);
await sendPasswordResetEmail(auth, email);
alert("Check your email for a password reset link.");
navigate("/");
} catch (error) {
console.error("Error during authentication:", error.message);
setError(error.message);
}
setLoading(false);
};
return (
<div>
<h2>New Forgot Password</h2>
{error && <p style={{ color: "red" }}>{error}</p>}
<form onSubmit={handleSubmit}>
<div>
<label>Email:</label>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
/>
</div>
<button disabled={loading} type="submit">
{"Reset Password"}
</button>
<Link to="/Login">Back to Login</Link>
</form>
</div>
);
};
export default ForgotPassword;