【发布时间】:2020-09-05 15:23:21
【问题描述】:
我正在使用云功能,并且正在尝试手动覆盖用户密码(我还设置了密码电子邮件重置)。
我可以成功更新用户编号、启用/禁用状态等,但是在传递密码变量时它似乎失败了,没有错误消息。
密码必须是“原始的、未散列的密码”。长度必须至少为六个字符。'
按照文档,我的云功能如下。
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 } ] }
【问题讨论】:
-
我不清楚您是否遇到错误。你写“它似乎失败了,没有错误消息。”,然后你提到似乎是错误消息“密码必须是'原始的、未散列的密码。必须至少六个字符长。”那么您说“当然,当我尝试使用测试帐户登录时,密码已设置为某些东西”?那么请问您的具体问题是什么?
-
这不是错误信息,是参考文档。运行时没有报错,但密码保持不变
-
Sorry 被更改为未知值
标签: javascript firebase firebase-authentication google-cloud-functions firebase-admin