Javascript 使用Meteor的自定义Github登录不起作用

Javascript 使用Meteor的自定义Github登录不起作用,javascript,login,meteor,Javascript,Login,Meteor,我一直在一步一步地关注此链接中显示的Eventedmind中的自定义登录教程: 所以我在Github上创建了一个新的应用程序,并对其进行了编码,但在运行Meteor时,我仍然存在错误,并且没有显示任何内容。我知道服务器端有错误,但我不知道是什么,可能代码写得不好,或者我调用登录名的方式不再合适。以下是我所做的(我想与教程中的相同) client/index.html <head> <title>App</title> </head> &

我一直在一步一步地关注此链接中显示的Eventedmind中的自定义登录教程:

所以我在Github上创建了一个新的应用程序,并对其进行了编码,但在运行Meteor时,我仍然存在错误,并且没有显示任何内容。我知道服务器端有错误,但我不知道是什么,可能代码写得不好,或者我调用登录名的方式不再合适。以下是我所做的(我想与教程中的相同)

client/index.html

<head>
    <title>App</title>
</head>

<body>
 {{> header}}
</body>

<template name="header">
    <div class="navbar navbar-inverse">
        <div class="navbar-inner">
            <div class="container">
                <a class="brand" href="#">NewApp</a>
            <form class="navbar-search pull-left">
                <input type="text" class="search-query" placeholder="Search">
            </form>
            <div class="nav pull_right">
                {{> user_info}}
            </div>
            </div>
        </div>
    </div>
</template>

<template name="user_info">
  <ul class="nav pull-right">
    {{#if currentUser}}
        {{> user_loggedin}}
    {{else}}
        {{> user_loggedout}}
    {{/if}}
  </ul>  
</template>


<template name="user_loggedin">
    {{#if loggingIn}}
        <li><a href="">Loggin in...</a></li>
    {{else}}
        <li>
            <img src="{{currentUser.profile.avatar_url}}" class="img-rounded" style="height: 32px; margin-top: 4px;">
        </li>
        <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                {{currentUser.profile.login}}
                <b class="caret"></b>
            </a>
            <ul class="dropdown-menu">
                <li><a href="">Accounts Settings</a></li>
                <li class="divider"></li>
                <li><a id="logout">logout</a></li>
            </ul>
        </li>
    {{/if}}
</template>


<template name="user_loggedout">
  <li><a id="login">Login with Github</a></li>
</template>
server/config.js

Accounts.loginServiceConfiguration.remove({
    service: "github"
});

Accounts.loginServiceConfiguration.insert({
    service: "github",
    clientId: "NUMBER",
    secret: "SECRET_NUMBER"
});
server/accounts.js

Accounts.onCreateUser(function (options, user) {
    var accessToken = user.services.github.accessToken,
        result,
        profile;
    result = Meteor.http.get("https://api.github.com/user", {
        params: {
            access_token: accessToken
        }
    });
    if (result.error)
        throw result.error;

    profile = _.pick(result.data,
        "login",
        "name",
        "avatar_url",
        "url",
        "company",
        "blog",
        "location",
        "email",
        "bio",
        "html_url");

    user.profile = profile;

    return user;
});

如果在页面上根本看不到任何渲染

在client/index.js中尝试添加

if (Meteor.isClient) {
    Meteor.Router.add({
      '/': 'index'  
    });
}
我是meteor的新手,但我认为当你在/client/目录结构中放置一些东西时,你必须路由到它

我可能错了,但您也可以尝试将所有内容都放在根文件夹中,并使用

if(Meteor.isClient)
和服务器的东西

if(Meteor.isServer)

我真的不知道你是说页面上什么都没有呈现,还是只是在你登录后才呈现。

最新的github API要求在每个请求中都有HTTP用户代理头。只需将其包括在下面

result = Meteor.http.get("https://api.github.com/user", {
  headers: {"User-Agent": "Meteor/1.0"},
  params: {
    access_token: accessToken
  }
});

Meteor将以“客户端模式”自动加载index.js。来自@pallavi anderson的解决方案非常有效
result = Meteor.http.get("https://api.github.com/user", {
  headers: {"User-Agent": "Meteor/1.0"},
  params: {
    access_token: accessToken
  }
});