我正在尝试使用 firebase admin SDK 来链接电子邮件/密码登录方法。
根据 firebase 文档,我们可以将用户链接到特定提供商 https://firebase.google.com/docs/reference/admin/node/firebase-admin.auth.updaterequest.md#updaterequestprovidertolink
基于我正在使用的:
await admin
.auth()
.updateUser(user.uid, {
providerToLink: {
uid: user.email,
email: user.email,
displayName: user.displayName,
providerId: 'password',
},
})
.catch((error: any) => {
console.error(`${error}`);
});
它应该将电子邮件/密码登录方法链接到特定用户,但它不会返回错误
auth/invalid-provider-id
The providerId must be a valid supported provider identifier string.
facebook.com
或google.com
问题
我应该使用另一个提供商 ID 来链接电子邮件/密码登录方法吗?
我应该使用另一种方法来链接电子邮件/密码登录方法吗?
节点版本:12
firebase-管理:9.12.0
您需要将providerId设置为“电子邮件”并提供密码。
await admin.auth().updateUser(user.uid, {
password: "password",
providerToLink: {
email: "[email protected]",
uid: "[email protected]",
providerId: 'email',
},
})
您可以将电子邮件和密码提供商链接到匿名用户,使用管理 SDK 更新用户
admin.auth().updateUser("xxxxx", {
email: "[email protected]",
password: "abc123"
});
运行此代码后,您将能够使用该凭据登录。