我正在逐步遵循 Eventedmind 的自定义登录教程,该教程显示在此链接中:
https://www.eventedmind.com/posts/meteor-customizing-login
所以我在 Github 上创建了一个新的应用程序并对其进行了编码,但是在运行 Meteor 时我仍然有错误并且没有任何显示。我知道我从服务器端收到错误,但我不知道它是什么,也许代码写得不好,或者我调用登录的方式不再正确。这是我所做的(我猜与教程中的相同)
客户端/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>
客户端/index.js
Template.user_loggedout.events({
'click #login': function (e, tmpl) {
Meteor.loginWithGithub({
requestPermissions: ['user', 'public_repo']
}, function (err) {
if (err) {
// error handling
} else {
// show alert
}
});
}
});
Template.user_loggedin.events({
'click #logout': function (e, tmpl) {
Meteor.logout(function (e, tmpl) {
if (err) {
// show err message
} else{
// show alert that says logged out
}
});
}
});
服务器/config.js
Accounts.loginServiceConfiguration.remove({
service: "github"
});
Accounts.loginServiceConfiguration.insert({
service: "github",
clientId: "NUMBER",
secret: "SECRET_NUMBER"
});
服务器/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;
});