Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor.js loginWithGoogle什么也不做_Meteor_Meteor Accounts - Fatal编程技术网

Meteor.js loginWithGoogle什么也不做

Meteor.js loginWithGoogle什么也不做,meteor,meteor-accounts,Meteor,Meteor Accounts,我正在开发我的第一个Meteor应用程序,它使用OAuth进行登录。在此之前,我的所有项目都只使用了帐户密码部分 我有一个简单的登录按钮,通过谷歌登录: <template name="login"> <form id="login" role="form"> <div class="form-group"> <label for="username">Username:</label> <in

我正在开发我的第一个Meteor应用程序,它使用OAuth进行登录。在此之前,我的所有项目都只使用了帐户密码部分

我有一个简单的登录按钮,通过谷歌登录:

<template name="login">
  <form id="login" role="form">
    <div class="form-group">
      <label for="username">Username:</label>
      <input type="text" id="username" name="username" class="form-control" placeholder="Username" />
    </div>
    <div class="form-group">
      <label for="password">Password:</label>
      <input type="password" id="password" name="password" class="form-control" placeholder="Password" />
    </div>
    <button id="signin" class="btn btn-primary">Sign in</button>
    <hr />
    Or:<br />
    <button id="loginWithFacebook">Login with Facebook</button>
    <button id="loginWithGoogle">Login with Google</button>
    <button id="loginWithTwitter">Login with Twitter</button>
  </form>
</template>
在服务器上,我为Google设置了OAuth,如下所示:

ServiceConfiguration.configurations.remove({
  service: "google"
});
ServiceConfiguration.configurations.insert({
  service: "google",
  clientId: "000000000000000",
  loginStyle: "popup",
  secret: "000000000"
});

Accounts.onCreateUser(function (options, user) {
  console.log('Creating user: ' + user.username);
  return user;
});
在我的路线上,我有:

if (Meteor.isClient) {
    // Initialize the loading template before hand
    Router.onBeforeAction('loading');

    // Map the routes
    Router.map(function() {
        // Homepage
        this.route('home', {
            path: '/',
            onBeforeAction: function() {
              if (!Meteor.user()) {
                console.log('User is not logged in. Displaying login form.');
                Router.go('login');
              } else {
                console.log('User is already logged in:', Meteor.user());
              }
            }
        });

        // Login page
        this.route('login', {
            path: '/login'
        });
    });
}

因此,我在浏览器中得到控制台日志,上面说
用户未登录。显示登录表单。
,当我单击使用谷歌登录按钮时,我会弹出询问我要使用哪个谷歌帐户的弹出窗口,然后是确认页面。但是当我点击“接受”按钮时,我什么也没有得到。
Accounts.onCreateUser()
似乎没有运行,
loginWithGoogle()上的回调代码也没有运行。如何正确配置此选项,以便回调运行,并最终将我重新定向回主页?

您的
onCreateUser
无法工作,因为您没有指定用户名

试用

 if(user.services.google)
       user.username = user.services.google.name

顺便问一下,你为什么不使用
{{>loginButtons}

尝试在meteor.com上部署你的项目,然后检查登录是否正常。如果这是来自google/server或你的代码的回调问题,你至少会得到修复。你知道我是否必须处理重定向URL,或者,这是作为谷歌账户包的一部分处理的?我从未尝试过使用google+,但我遇到了FB的问题,因为在端口3000上提供服务是有问题的。这就是为什么我建议在官方的meteor.com网站上尝试,那里的一切都应该是开箱即用的(当然,你需要给出正确的客户ID和秘密)。这个包不会为你重定向(路由)任何东西。正如我所说的,这是我第一次尝试更复杂的登录过程,所以我没有意识到
{{>loginButtons}
,或者至少在我创建基本登录页面时,它没有在我脑海中触发。不过,我肯定会转向这一点。我还将尝试您关于更改onCreateUser的
onCreateUser
的建议,并尽快查看是否有效。问题似乎是未使用
{{loginButtons}
和未正确打印用户的组合。谢谢你给我指出了正确的位置。
 if(user.services.google)
       user.username = user.services.google.name