流星:设置帐户-github不工作

时间:2014-06-06 09:49:21

标签: authentication meteor github-api

我尝试使用github设置身份验证。 我跟着documentation。我已经安装了这些软件包:

$> meteor add accounts-github
$> meteor add service-configuration

我在server/github.js中的代码如下:

ServiceConfiguration.configurations.remove({
    service: "github"
});
ServiceConfiguration.configurations.insert({
    service: "github",
    clientId: '****',
    secret: '*************'
});

Meteor.loginWithGithub({
    requestPermissions: ['user', 'public_repo']
}, function (err) {
      if (err)
        Session.set('errorMessage', err.reason || 'Unknown error');
});

当我启动meteor时,我收到以下错误:

/Users/me/.meteor/tools/5bf1690853/lib/node_modules/fibers/future.js:173
                    throw(ex);
                          ^
TypeError: Object #<Object> has no method 'loginWithGithub'
at app/server/github.js:11:8
at app/server/github.js:18:3
....

所以似乎Meteor对象没有loginWithGithub方法。有什么建议吗?

1 个答案:

答案 0 :(得分:3)

您正在应用的/server目录中运行代码。

通常您从Web浏览器调用此代码,以使Meteor显示Github OAuth登录对话框。

这在服务器上不可用,因为它只能在浏览器端工作。这就是您看到此错误的原因。

您通常会在事件侦听器中触发Meteor.loginWithGithub(),以便他们在单击按钮或某个UI元素时开始登录过程。

要记住的另一件事是SessionSession.getSession.set等)也只能在客户端上工作。

要查看哪些方法在使用Meteor documentation的位置运行。在每个方法的上角,它显示了代码可以运行的位置:Client,Server或Anywhere。

相关问题