在 Meteor 中使用 OAUTH 处理重复帐户的实用方法? [英] Practical ways of dealing with duplicate accounts using OAUTH in Meteor?

查看:44
本文介绍了在 Meteor 中使用 OAUTH 处理重复帐户的实用方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在 Meteor 中有 Facebook、Google 和用户名/密码登录包.none@example.com 电子邮件的用户使用此电子邮件和密码注册.后来他忘记了他以前注册过,并再次使用 Facebook 注册.他的 Facebook 电子邮件地址也是 none@example.com.

Say that I've got the Facebook, Google, and Username/Password login packages in Meteor. A user with an email of none@example.com signs up using this email and password. Then later he forgets that he has signed up before, and signs up again using Facebook. His Facebook email is also none@example.com.

所以现在我们有一个人拥有两个不同的帐户.这很糟糕且令人困惑,特别是如果用户使用 Facebook 登录并且无法找到他在电子邮件/密码系统下创建的订单历史记录等用户数据.

So now we've got one person with two different accounts. This is bad and confusing, especially if the user logs in using Facebook and can't find his user data like order history which he had created under the Email/Password system.

是否有允许用户混合和匹配登录方法但仍保持连续性的软件包?

Is there a package out there that allows a user to mix and match login methods but still maintaining continuity?

我不喜欢 OAUTH 用户将他们的电子邮件隐藏在 services.google/facebook.email 中,而是希望它只是在普通的 emails 数组中.

I didn't like that OAUTH users had their emails buried inside services.google/facebook.email and instead want it to just be inside the normal emails array.

var returnUserEmail = function(userDoc){
    if(userDoc.services.google){
        return userDoc.services.google.email;
    } else if (userDoc.services.facebook){
        return userDoc.services.facebook.email;
    } else {
        return userDoc.emails[0].address;
    };
};

Accounts.onCreateUser(function(options, user) {

    console.log("user created! ", user);

    if (!user.emails){
        var email = returnUserEmail(user);
        user.emails = [];
        user.emails[0] = {};
        user.emails[0].address = email;
        user.emails[0].verified = true;
        // This function simply updates the user document
        updateCollectionDocument(Meteor.users, user);
    };

  return user;

});

随着这段代码的运行,如果用户首先使用电子邮件/密码注册,然后尝试使用 Facebook 注册,登录屏幕将给他一条错误消息,指出电子邮件已经存在.现在他无法享受登录 Facebook 的好处.

With this bit of code running, if a user signs up first using email/password and then tries to sign up using Facebook, the login screen will give him an error message saying that the email already exists. And now he cannot enjoy the benefits of signing in with Facebook.

所以现在我觉得有些不对劲.是否有一个逻辑流程可以让所有这些登录/注册方法协同工作,同时保持连续性?

So now something doesn't feel right to me. Is there a logic flow where I can have all of these login/registration methods work together but also maintain continuity?

推荐答案

您正在寻找这个包 https://github.com/splendido/meteor-accounts-meld

accounts-meld 尝试解决以下几个方面:

accounts-meld tried to address the following aspects:

  1. 不能存在两个使用同一电子邮件地址注册的帐户

  1. No two accounts registered with the same email address can exist

许多不同的 3rd-party 登录服务可以与相同的用户帐号

Many different 3rd-party login services could be associated with the same user account

在不同时间创建的不同帐户引用到同一个电子邮件地址可能/应该合并在一起.

Different accounts created in different times referring to the same email address might/should be melded together.

我以前用过它,效果很好,我的工作流程是强制电子邮件验证(重要)之后,帐户融合可以将具有相同电子邮件的帐户合并到一个,并且用户可以使用社交登录.(也可以询问用户是否愿意这样做)

I have used it before and it works great, My work flow was to force email verification (important) after that account-meld can merge accounts with the same emails to one and the user can use the social login. (Also it's possible to ask the user if they want to do that)

这篇关于在 Meteor 中使用 OAUTH 处理重复帐户的实用方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆