gpt4 book ai didi

meteor - meteor 用户的多个帐户

转载 作者:行者123 更新时间:2023-12-01 13:44:52 29 4
gpt4 key购买 nike

在我的 meteor-angular 应用程序中,我配置了 2 个帐户登录:Facebook 和谷歌

现在,假设用户 A 使用他的 Facebook 帐户登录。登录后,我将用户发送到另一个表单页面以插入他的社交 ID(此表单页面仅向用户显示一次)。

所以现在我有一个用户对象(Meteor.user() + 他的社交 ID)。

用户正在应用程序中工作并插入他的 Assets 。

现在用户决定注销。

一段时间后,他返回应用程序,这次他使用他的 Google 帐户登录。所以现在他将再次被重定向到“插入社交 ID”页面表单,因为在数据库中创建了一个新用户。

有没有办法绑定(bind)这两个用户?我有一个唯一标识符(社交 ID),可以帮助我合并它们,但找不到进行绑定(bind)的方法...

我需要那个绑定(bind),因为如果他使用不同的 ID 登录,他将无法编辑他的 Assets ...

10倍

最佳答案

使用 onCreateUser打回来。查找已使用该社交 ID 注册的用户,如果存在,则只需将新服务对象添加到现有用户文档即可。

Accounts.onCreateUser(function (options, user) {
// Find an existing user based on social ID
let registeredUser = Meteor.users.findOne(...);

if(registeredUser) {
let googleProfile = user.services.google;

if (googleProfile) {
// Add Google login credentials to the user document in Mongo
Meteor.users.update({...}, {$set: {"services.google": googleProfile});
}

// throw an Error here to stop creating a new user.
}

// Returning a user object will create a new one in Mongo.
return user;
});

免责声明:我一般会建议反对合并用户。请注意,窃取您的 Facebook 密码的恶意攻击者也可能窃取您在此服务中的数据,即使您仅使用 Google 注册也是如此。

关于meteor - meteor 用户的多个帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36715218/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com