首页 > 解决方案 > 在 Firebase Auth REST API 中的“更改密码”POST 请求后,我无法获得 refreshToken

问题描述

我正在尝试使用 Firebase Auth REST API 文档中的“更改密码”部分更改用户密码。我提出请求。我收到了回复,但我的回复中没有 refreshToken。

这是我的要求:

export const changePassword = async (token,password) => {
  const response = await fetch(
    'https://identitytoolkit.googleapis.com/v1/accounts:update?key=[API_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);

这是我的console.log(resData);下面:

email: "email@gmail.com"
emailVerified: false
kind: "identitytoolkit#SetAccountInfoResponse"
localId: "localId..."
passwordHash: "UkVEQUNURUQ="
providerUserInfo: [{…}]

这就是我得到的。我不知道下一步该做什么,这是一个紧急项目。我没有任何刷新令牌。我怎样才能得到它,如果我得到它,我下一步该怎么做?

谢谢

标签: firebasefirebase-realtime-databasefirebase-authenticationrestrefresh-token

解决方案


推荐阅读