MongoDB Stitch:linkWithCredential给出了无效的用户名/密码



我正在制作一个 React Native 应用程序。我一直在用户进入应用程序时实现匿名登录。执行某些操作后,用户可以注册。当我尝试将当前匿名用户与电子邮件和密码链接时,它说[StitchServiceError:用户名/密码无效]。我不知道为什么。我一直在遵循完全相同的文档来链接与凭据。

这是我的代码:

const auth = Stitch.defaultAppClient.auth;
const collection = Stitch.defaultAppClient
.getServiceClient(RemoteMongoClient.factory, 'mongodb-atlas')
.db('snack')
.collection('users');
const {email, password, ...rest} = currentUser;
return from(
auth.user.linkWithCredential(
new UserPasswordCredential(email, password),
),
).pipe(switchMap(() => .....))

我正在使用Redux Observable来产生副作用。

我在设置中启用了电子邮件/密码和匿名身份验证。我不知道这里出了什么问题,为什么当我尝试注册和链接用户时会给我用户名和密码错误。

啊,愚蠢。我来自火力基地背景。所以认为它会以同样的方式工作。但事实并非如此。

因此,我必须先创建一个帐户。然后链接它。在火力基地。您可以直接链接该帐户,他们会创建一个新帐户,并自动将其与您的匿名会话相关联。

以下是更新的代码:

const {email, password, ...rest} = currentUser;
const emailPasswordClient = Stitch.defaultAppClient.auth.getProviderClient(
UserPasswordAuthProviderClient.factory,
);
return from(
emailPasswordClient.registerWithEmail(email, password),
).pipe(
switchMap(() => {
return from(
auth.user.linkWithCredential(
new UserPasswordCredential(email, password),
),
).pipe(
switchMap(() => ...)
.....)

最新更新