Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do some console ops for visual tracking in authentication routine #820

Merged
merged 1 commit into from
Nov 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var isDbg = require('../libs/debug').isDbg;
var passport = require('passport');
var jwt = require('jwt-simple');
var url = require('url');
var chalk = require('chalk');

//--- Model inclusions
var Strategy = require('../models/strategy.js').Strategy;
Expand Down Expand Up @@ -207,21 +208,47 @@ exports.callback = function (aReq, aRes, aNext) {
// This callback will happen after the verify routine
var authenticate = passport.authenticate(strategy, function (aErr, aUser, aInfo) {
if (aErr) {
// Some possible catastrophic error with *passport*... and/or authentication
console.error(chalk.red(aErr));
if (aInfo) {
console.warn(chalk.yellow(aInfo));
}

aNext(aErr);
return;
}

// If there is some info from *passport*... display it only in development and debug modes
// This includes, but not limited to, `username is taken`
if ((isDev || isDbg) && aInfo) {
console.warn(chalk.yellow(aInfo));
}

if (!aUser) {
// If there is no User then authentication could have failed
// Only display if development or debug modes
if (isDev || isDbg) {
console.error(chalk.red('`User` not found'));
}

aRes.redirect(doneUrl + (doneUrl === '/' ? 'register' : '') + '?authfail');
return;
}

aReq.logIn(aUser, function (aErr) {
if (aErr) {
console.error('Not logged in');
console.error(aErr);

aNext(aErr);
return;
}

// Show a console notice that successfully logged in with development and debug modes
if (isDev || isDbg) {
console.log(chalk.green('Logged in'));
}

// Store the user info in the session
aReq.session.user = aUser;

Expand Down
5 changes: 3 additions & 2 deletions libs/githubClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var _ = require("underscore");
var async = require('async');
var util = require('util');
var request = require('request');
var chalk = require('chalk');

// Client
var github = new GitHubApi({
Expand All @@ -30,9 +31,9 @@ Strategy.findOne({ name: 'github' }, function (aErr, aStrat) {
key: aStrat.id,
secret: aStrat.key,
});
console.log('GitHub client authenticated');
console.log(chalk.green('GitHub client authenticated'));
} else {
console.warn('GitHub client NOT authenticated. Will have a lower Rate Limit.');
console.warn(chalk.yellow('GitHub client NOT authenticated. Will have a lower Rate Limit.'));
}

});
Expand Down