lib/authentication.js
function normalizeUserData() {
		function handler(req, res, next) {
			if (req.session && !req.session.user && req.session.auth && req.session.auth.loggedIn) {
				var user = {};
				if (req.session.auth.github) {
					user.image = 'http://1.gravatar.com/avatar/'+req.session.auth.github.user.gravatar_id+'?s=48';
					user.name = req.session.auth.github.user.name;
					user.id = 'github-'+req.session.auth.github.user.id;
				}
				if (req.session.auth.twitter) {
					user.image = req.session.auth.twitter.user.profile_image_url;
					user.name = req.session.auth.twitter.user.name;
					user.id = 'twitter-'+req.session.auth.twitter.user.id_str;
				}
				if (req.session.auth.facebook) {
					user.image = req.session.auth.facebook.user.picture;
					user.name = req.session.auth.facebook.user.name;
					user.id = 'facebook-'+req.session.auth.facebook.user.id;

					// Need to fetch the users image...
					https.get({
						'host': 'graph.facebook.com'
						, 'path': '/me/picture?access_token='+req.session.auth.facebook.accessToken
					}, function(response) {
						user.image = response.headers.location;
						req.session.user = user;
						next();
					}).on('error', function(e) {
						req.session.user = user;
						next();
					});
					return;
				}
				req.session.user = user;
			}
			next();
		}
		return handler;
	}
function normalizeUserData() {
		function handler(req, res, next) {
			if (req.session && !req.session.user && req.session.auth && req.session.auth.loggedIn) {
				var user = {};
				if (req.session.auth.github) {
					user.image = 'http://1.gravatar.com/avatar/'+req.session.auth.github.user.gravatar_id+'?s=48';
					user.name = req.session.auth.github.user.name;
					user.id = 'github-'+req.session.auth.github.user.id;
				}
				if (req.session.auth.twitter) {
					user.image = req.session.auth.twitter.user.profile_image_url;
					user.name = req.session.auth.twitter.user.name;
					user.id = 'twitter-'+req.session.auth.twitter.user.id_str;
				}
				if (req.session.auth.facebook) {
					user.image = req.session.auth.facebook.user.picture;
					user.name = req.session.auth.facebook.user.name;
					user.id = 'facebook-'+req.session.auth.facebook.user.id;

					// Need to fetch the users image...
					https.get({
						'host': 'graph.facebook.com'
						, 'path': '/me/picture?access_token='+req.session.auth.facebook.accessToken
					}, function(response) {
						user.image = response.headers.location;
						req.session.user = user;
						next();
					}).on('error', function(e) {
						req.session.user = user;
						next();
					});
					return;
				}
				req.session.user = user;
			}
			next();
		}
		return handler;
	}
function normalizeUserData ( ) { function handler ( req , res , next ) { if ( req . session && ! req . session . user && req . session . auth && req . session . auth . loggedIn ) { var user = { } ; if ( req . session . auth . github ) { user . image = 'http://1.gravatar.com/avatar/' + req . session . auth . github . user . gravatar_id + '?s=48' ; user . name = req . session . auth . github . user . name ; user . id = 'github-' + req . session . auth . github . user . id ; } if ( req . session . auth . twitter ) { user . image = req . session . auth . twitter . user . profile_image_url ; user . name = req . session . auth . twitter . user . name ; user . id = 'twitter-' + req . session . auth . twitter . user . id_str ; } if ( req . session . auth . facebook ) { user . image = req . session . auth . facebook . user . picture ; user . name = req . session . auth . facebook . user . name ; user . id = 'facebook-' + req . session . auth . facebook . user . id ; // Need to fetch the users image... https . get ( { 'host' : 'graph.facebook.com' , 'path' : '/me/picture?access_token=' + req . session . auth . facebook . accessToken } , function ( response ) { user . image = response . headers . location ; req . session . user = user ; next ( ) ; } ) . on ( 'error' , function ( e ) { req . session . user = user ; next ( ) ; } ) ; return ; } req . session . user = user ; } next ( ) ; } return handler ; }
Fetch and format data so we have an easy object with user data to work with.
Fetch and format data so we have an easy object with user data to work with .