@@ -11,6 +11,7 @@ var isDbg = require('../libs/debug').isDbg;
1111var passport = require ( 'passport' ) ;
1212var jwt = require ( 'jwt-simple' ) ;
1313var url = require ( 'url' ) ;
14+ var chalk = require ( 'chalk' ) ;
1415
1516//--- Model inclusions
1617var 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
0 commit comments