Skip to content

Commit bece4ab

Browse files
author
Martii
committed
Do some console ops for visual tracking in authentication routine
* Also trying out *chalk* dep to see if the VPS pro logs can handle this without too much visual interference... nicer in development and debug modes... if not will remove. Applies to Code Migrations, #430, and jaredhanson/passport#400 (comment) Still getting `username is taken` with *passport*@0.3.2 and *passport-github*@1.0.0 but **not** *passport*@0.2.2 with *passport-github*@0.1.5
1 parent 10a15a5 commit bece4ab

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

controllers/auth.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var isDbg = require('../libs/debug').isDbg;
1111
var passport = require('passport');
1212
var jwt = require('jwt-simple');
1313
var url = require('url');
14+
var chalk = require('chalk');
1415

1516
//--- Model inclusions
1617
var Strategy = require('../models/strategy.js').Strategy;
@@ -207,21 +208,47 @@ exports.callback = function (aReq, aRes, aNext) {
207208
// This callback will happen after the verify routine
208209
var authenticate = passport.authenticate(strategy, function (aErr, aUser, aInfo) {
209210
if (aErr) {
211+
// Some possible catastrophic error with *passport*... and/or authentication
212+
console.error(chalk.red(aErr));
213+
if (aInfo) {
214+
console.warn(chalk.yellow(aInfo));
215+
}
216+
210217
aNext(aErr);
211218
return;
212219
}
213220

221+
// If there is some info from *passport*... display it only in development and debug modes
222+
// This includes, but not limited to, `username is taken`
223+
if ((isDev || isDbg) && aInfo) {
224+
console.warn(chalk.yellow(aInfo));
225+
}
226+
214227
if (!aUser) {
228+
// If there is no User then authentication could have failed
229+
// Only display if development or debug modes
230+
if (isDev || isDbg) {
231+
console.error(chalk.red('`User` not found'));
232+
}
233+
215234
aRes.redirect(doneUrl + (doneUrl === '/' ? 'register' : '') + '?authfail');
216235
return;
217236
}
218237

219238
aReq.logIn(aUser, function (aErr) {
220239
if (aErr) {
240+
console.error('Not logged in');
241+
console.error(aErr);
242+
221243
aNext(aErr);
222244
return;
223245
}
224246

247+
// Show a console notice that successfully logged in with development and debug modes
248+
if (isDev || isDbg) {
249+
console.log(chalk.green('Logged in'));
250+
}
251+
225252
// Store the user info in the session
226253
aReq.session.user = aUser;
227254

libs/githubClient.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var _ = require("underscore");
1111
var async = require('async');
1212
var util = require('util');
1313
var request = require('request');
14+
var chalk = require('chalk');
1415

1516
// Client
1617
var github = new GitHubApi({
@@ -30,9 +31,9 @@ Strategy.findOne({ name: 'github' }, function (aErr, aStrat) {
3031
key: aStrat.id,
3132
secret: aStrat.key,
3233
});
33-
console.log('GitHub client authenticated');
34+
console.log(chalk.green('GitHub client authenticated'));
3435
} else {
35-
console.warn('GitHub client NOT authenticated. Will have a lower Rate Limit.');
36+
console.warn(chalk.yellow('GitHub client NOT authenticated. Will have a lower Rate Limit.'));
3637
}
3738

3839
});

0 commit comments

Comments
 (0)