如何解决如何使用 Firebase Rest API 更改密码?
我正在尝试使用 Rest API post 请求更改用户密码,如下所示:
export const changePassword = async (userId,token,expirationTime,password) => {
const response = await fetch(
'https://identitytoolkit.googleapis.com/v1/accounts:update?key=[MY_KEY]',{
method: 'POST',headers: {
'Content-type': 'application/json',},body: JSON.stringify({
idToken: token,password: password.newPassword,returnSecureToken: true,}),);
if (!response.ok) {
const errorResData = await response.json();
const errorId = errorResData.error.message;
let message = 'Something went wrong!';
if (errorId === 'EMAIL_NOT_FOUND') {
message = 'This e-mail can not be found.';
} else if (errorId === 'INVALID_PASSWORD') {
message = 'This password is invalid!';
}
throw new Error(message);
}
const resData = await response.json();
console.log(resData);
alert('Password changed successfully!')
};
我正确地获得了 idToken,但我不知道下一步该怎么做。我的 resData 如下所示:
email: "rachel.green@gmail.com"
emailVerified: false
kind: "identitytoolkit#SetAccountInfoResponse"
localId: "FXPwA0n1f1RIqliLOx0tLkhgORy1"
passwordHash: "UkVEQUNURUQ="
providerUserInfo: Array(1)
我知道我需要使用 refreshToken 做某事但需要帮助。 这是用于身份验证的 Firebase Rest API 文档:https://firebase.google.com/docs/reference/rest/auth#section-api-usage
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。