Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(client:auth): redirect a logged-in user when visits a guest page …
…like /login or /signup
  • Loading branch information
mtvs committed Jul 25, 2016
commit 307898feea66958574fa859723e8a6cb27f233c8
6 changes: 4 additions & 2 deletions templates/app/client/app/account(auth)/account.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export default function routes($stateProvider) {
url: '/login',
template: require('./login/login.<%= templateExt %>'),
controller: 'LoginController',
controllerAs: 'vm'
controllerAs: 'vm',
guest: true
})
.state('logout', {
url: '/logout?referrer',
Expand All @@ -27,7 +28,8 @@ export default function routes($stateProvider) {
url: '/signup',
template: require('./signup/signup.<%= templateExt %>'),
controller: 'SignupController',
controllerAs: 'vm'
controllerAs: 'vm',
guest: true
})
.state('settings', {
url: '/settings',
Expand Down
45 changes: 28 additions & 17 deletions templates/app/client/components/auth(auth)/router.decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,46 @@ export function routerDecorator($rootScope<% if(filters.ngroute) { %>, $location
'ngInject';
// Redirect to login if route requires auth and the user is not logged in, or doesn't have required role
$rootScope.$on(<% if(filters.ngroute) { %>'$routeChangeStart'<% } %><% if(filters.uirouter) { %>'$stateChangeStart'<% } %>, function(event, next) {
if(!next.authenticate) {
return;
}
if(next.authenticate) {
if(typeof next.authenticate === 'string') {
Auth.hasRole(next.authenticate).then(has => {
if(has) {
return;
}

if(typeof next.authenticate === 'string') {
Auth.hasRole(next.authenticate).then(has => {
if(has) {
return;
}
event.preventDefault();
return Auth.isLoggedIn().then(is => {
<%_ if(filters.ngroute) { _%>
$location.path(is ? '/' : '/login');<% } %>
<%_ if(filters.uirouter) { _%>
$state.go(is ? 'main' : 'login');<% } %>
});
});
} else {
Auth.isLoggedIn().then(is => {
if(is) {
return;
}

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

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