Skip to content

Commit

Permalink
fix(app): redirect to login only on 401s
Browse files Browse the repository at this point in the history
  • Loading branch information
DaftMonk committed Feb 8, 2014
1 parent 667fc74 commit 64b7bac
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion templates/coffeescript/app.coffee
Expand Up @@ -22,9 +22,10 @@ angular.module('<%= scriptAppName %>', [<%= angularModules %>])<% if (ngRoute) {

$locationProvider.html5Mode true<% if (mongoPassportUser) { %>

# Intercept 401s and redirect you to login
$httpProvider.interceptors.push ['$q', '$location', ($q, $location) ->
responseError: (response) ->
if response.status is 401 or response.status is 403
if response.status is 401
$location.path '/login'
$q.reject response
else
Expand Down
2 changes: 1 addition & 1 deletion templates/express/controllers/users.js
Expand Up @@ -11,7 +11,7 @@ exports.create = function (req, res, next) {
var newUser = new User(req.body);
newUser.provider = 'local';
newUser.save(function(err) {
if (err) return next(err);
if (err) return res.json(400, err);

req.logIn(newUser, function(err) {
if (err) return next(err);
Expand Down
4 changes: 2 additions & 2 deletions templates/javascript/app.js
Expand Up @@ -26,11 +26,11 @@ angular.module('<%= scriptAppName %>', [<%= angularModules %>])<% if (ngRoute) {

$locationProvider.html5Mode(true);<% if (mongoPassportUser) { %>

// Intercept 401s and 403s and redirect you to login
// Intercept 401s and redirect you to login
$httpProvider.interceptors.push(['$q', '$location', function($q, $location) {
return {
'responseError': function(response) {
if(response.status === 401 || response.status === 403) {
if(response.status === 401) {
$location.path('/login');
return $q.reject(response);
}
Expand Down

0 comments on commit 64b7bac

Please sign in to comment.