Last active
November 9, 2016 00:28
-
-
Save 10thfloor/1f6652d644f965aa54d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$routeProvider.when = (function(when){ | |
var extendedWhen = function(incomingRoute, routeConfig){ | |
// Basic error case. | |
if(routeConfig.resolve && typeof routeConfig.resolve !== 'object'){ | |
throw new Error('$routeProvider.when: resolve should be \'object\' instead of: ' + typeof config.resolve ); | |
} | |
routeConfig = routeConfig || {}; | |
routeConfig.resolve = angular.extend(routeConfig.resolve, { | |
CHECK_FOR_LOGGED_IN_USER : ['waitForAuth','$rootScope', '$q', 'routingHelpers', | |
function(waitForAuth, $rootScope, $q, routingHelpers){ | |
var deferred = $q.defer(); | |
waitForAuth.then(function() { | |
if(routingHelpers.shouldRedirect(incomingRoute)){ | |
deferred.reject({'REDIRECT_ROUTE' : { attemptedRoute: incomingRoute, to: '/' }}); | |
}else{ | |
deferred.resolve(); | |
} | |
}); | |
return deferred.promise; | |
}] | |
}); | |
return when.apply(this, [incomingRoute, routeConfig]); | |
}; | |
return extendedWhen; | |
})($routeProvider.when); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment