将Google登录限制为Meteor中的.edu帐户 [英] Limit Google Sign-In to .edu accounts in Meteor

查看:119
本文介绍了将Google登录限制为Meteor中的.edu帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图将我的Google +登录按钮限制为仅允许@ something.edu帐户登录.我将如何去做.到目前为止,这是我的代码:

I'm trying to limit my Google + Sign-In Button to only allow @something.edu accounts to sign in. How would I go about doing this. This is my code so far:

Template.googleLogin.events({
    'click #gLogin': function(event) {
        Meteor.loginWithGoogle({}, function(err){
            if (err) {
                throw new Meteor.Error("Google login didn't work!");
            }
            else {
                Router.go('/home')
            }


        });
    }
})

Template.primaryLayout.events({
    'click #gLogout': function(event) {
        Meteor.logout(function(err){
            if (err) {
                throw new Meteor.Error("Hmm looks like your logout failed. ");
            }
            else {
                Router.go('/')
            }
        })
    }
})

推荐答案

您可以使用Accounts.config(在根目录中,因此它可以在客户端和服务器上运行)来完成此操作

You can accomplish this using Accounts.config (in the root directory, so it runs on both the client and server)

Accounts.config({ restrictCreationByEmailDomain: 'something.edu' })

如果您需要更多自定义内容,则可以在需要细化需求的情况下用一种方法替换something.edu,例如,对于任何.edu域:

If you need something more custom, you can replace something.edu with a method if you need to fine grain your requirement, i.e for any .edu domain:

Accounts.config({ restrictCreationByEmailDomain: function(address) {
        return new RegExp('\\.edu$', 'i')).test(address)
    }
});

这篇关于将Google登录限制为Meteor中的.edu帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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