Skip to content

Commit

Permalink
fix(client:auth): fix auth 'decorator'
Browse files Browse the repository at this point in the history
closes #1492
  • Loading branch information
Awk34 committed Dec 13, 2015
1 parent ecf9014 commit 56d12fc
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions app/templates/client/components/auth(auth)/router.decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,29 @@ angular.module('<%= scriptAppName %>.auth')
return;
}

let query = typeof next.authenticate === 'string' ? Auth.hasRole : Auth.isLoggedIn;
if(typeof next.authenticate === 'string') {
Auth.hasRole(next.authenticate, _.noop).then(has => {
if(has) {
return;
}

query(1,2).then(good => {
if(!good) {
event.preventDefault();
Auth.isLoggedIn().then(is => {<% if (filters.ngroute) { %>
return Auth.isLoggedIn().then(is => {<% if (filters.ngroute) { %>
$location.path(is ? '/' : '/login');<% } if (filters.uirouter) { %>
$state.go(is ? 'main' : 'login');<% } %>
});
}
});
})
} else {
Auth.isLoggedIn(_.noop).then(is => {
if(is) {
return;
}

event.preventDefault();<% if (filters.ngroute) { %>
$location.path('/');<% } if (filters.uirouter) { %>
$state.go('main');<% } %>
});
}
});
});

Expand Down

0 comments on commit 56d12fc

Please sign in to comment.