Javascript Firebase管理SDK未按预期更新密码

Javascript Firebase管理SDK未按预期更新密码,javascript,firebase,firebase-authentication,google-cloud-functions,firebase-admin,Javascript,Firebase,Firebase Authentication,Google Cloud Functions,Firebase Admin,我正在使用云功能,并试图手动覆盖用户密码(我还设置了密码电子邮件重置) 我可以成功地更新用户号码、启用/禁用状态等,但是当传递密码变量时,它似乎失败了,没有错误消息 密码必须是“原始、未删除的密码”。必须至少有六个字符长。” 在文档之后,我的云功能如下 exports.resetUserPassword = functions.https.onCall(async (data, context) => { if (!context.auth.token.superadmin) ret

我正在使用云功能,并试图手动覆盖用户密码(我还设置了密码电子邮件重置)

我可以成功地更新用户号码、启用/禁用状态等,但是当传递密码变量时,它似乎失败了,没有错误消息

密码必须是“原始、未删除的密码”。必须至少有六个字符长。”

在文档之后,我的云功能如下

exports.resetUserPassword = functions.https.onCall(async (data, context) => {

  if (!context.auth.token.superadmin) return

  try {
    console.log(data.password)
    admin.auth().updateUser(data.uid, {
      password: 'testpassword',
    })
      .then(function(userRecord) {
        // See the UserRecord reference doc for the contents of userRecord.
        console.log("Successfully updated user", userRecord.toJSON());
      })
      .catch(function(error) {
        console.log("Error updating user:", error);
      });

    return true
  } catch (error) {
    console.log(error)
  }

});
当我查看firebase函数的日志时,响应似乎表明密码尚未更新(当然,当我尝试使用测试帐户登录时,密码已设置为…IDK…)。请注意,passwordHash和passwordSalt未定义

Successfully updated user { uid: 'HMxo5NcObYTN5LPsgSb0ZTCK6213',
  email: 'test@test.com',
  emailVerified: false,
  displayName: undefined,
  photoURL: undefined,
  phoneNumber: undefined,
  disabled: false,
  metadata: 
   { lastSignInTime: 'Tue, 19 May 2020 00:36:16 GMT',
     creationTime: 'Tue, 19 May 2020 00:36:16 GMT' },
  passwordHash: undefined,
  passwordSalt: undefined,
  customClaims: { customer: true },
  tokensValidAfterTime: 'Tue, 19 May 2020 13:50:02 GMT',
  tenantId: undefined,
  providerData: 
   [ { uid: 'test@test.com',
       displayName: undefined,
       email: 'test@test.com',
       photoURL: undefined,
       providerId: 'password',
       phoneNumber: undefined } ] }


您的代码忽略了由
updateUser().then().catch()
返回的承诺。所有异步工作完成后,可调用函数需要返回一个承诺,该承诺与发送给调用方的响应一起解析。现在,您的函数只返回
true
,并在
updateUser
的工作实际完成之前立即完成

为了让工作能够完成,您应该返回承诺链,并指出调用者应该收到什么:

return admin.auth().updateUser(...)
.then(() => {
    return "whatever you want the client to receive on success"
})
.catch(error => {
    return "whatever you want the client to receive on error"
})

我不清楚你是否遇到了错误。你写了“似乎失败了,没有错误消息”。然后你提到了一条错误消息“密码必须是‘原始的、未加密的密码。必须至少有六个字符长”。然后你说“当然,当我尝试使用测试帐户登录时,密码已设置为某个值”?那么,您的确切问题是什么呢?这不是错误消息,而是参考文档。运行此操作时没有引发任何错误,但密码保持不变,或者更改为未知值。这对我不起作用。我尝试在节点shell中调用
updateUser
,并观察到它正确地更新了
displayName
等字段,但
passwordHash
passwordSalt
字段仍然未定义