Saturday, 14 September 2013

Custom Login with Github is not working

Custom Login with Github is not working

I've being following step by step the Custom Login tutorial from
Eventedmind showing in this link:
https://www.eventedmind.com/posts/meteor-customizing-login
So I've created a new App on Github and code it but while running Meteor I
still have errors and nothing shows up. I know I've got errors from the
server side, but I have no idea what is it, maybe the code is bad written
or maybe the way I am calling the login is not the proper anymore. Here is
what I've done (I guess is the same as in the tutorial)
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="#">Surf</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>
client/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
}
});
}
});
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;
});

No comments:

Post a Comment