2013-10-27 72 views
3

Meteor提供了一组loginWithExternalService()方法(例如loginWithTwitter()),该方法允许用户创建帐户或使用这些第三方认证提供程序重新登录。区分使用Meteor.loginWithExternalService()登录和登录

但有没有办法区分两种行为?即让人在Twitter上登录,而不必让他们通过相同的动作注册

实际使用情况是其中的注册数量被限制一个网站,你有一个私人网址签署,但对于签署一个公共页面。我正在寻找一种方法来防止人们仅通过首次登录就能创建帐户。

回答

1

你很可能钩到Accounts.onCreateUser(服务器端)

像这样的东西可能会有所帮助:

服务器端JS

Accounts.onCreateUser(function(options, user) { 

    //Check if this user can be created, if not throw an error 
    var canCreate = false 

    if(!canCreate) 
     throw new Meteor.Error(403, 'You cant sign up', "Sorry you can only sign in but not sign up"); 

    //Create the user like normal if we can. 
    if (options.profile) 
    user.profile = options.profile; 
    return user; 
}); 

投掷错误阻止方法无法返回,创造一个帐户。它只在有人创建账户但没有账户的情况下运行(外部服务提供者)

在客户端上,您可以处理错误,但在accounts-ui软件包中会出现“内部服务器错误”消息。你可以定制这个'你需要成为一个管理员'或其他东西