Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Redirect if not logged in #1475

Closed
frkwhiteangel opened this issue Sep 2, 2016 · 3 comments
Closed

Redirect if not logged in #1475

frkwhiteangel opened this issue Sep 2, 2016 · 3 comments
Assignees
Milestone

Comments

@frkwhiteangel
Copy link

Is there a way to redirect a user if not logged in into the login view?

@lirantal
Copy link
Member

lirantal commented Sep 2, 2016

@simison , @mleanos ?

@simison
Copy link
Member

simison commented Sep 2, 2016

Suppose you should modify this somehow:

function stateChangeStart(event, toState, toParams, fromState, fromParams) {
// Check authentication before changing state
if (toState.data && toState.data.roles && toState.data.roles.length > 0) {
var allowed = false;
for (var i = 0, roles = toState.data.roles; i < roles.length; i++) {
if ((roles[i] === 'guest') || (Authentication.user && Authentication.user.roles !== undefined && Authentication.user.roles.indexOf(roles[i]) !== -1)) {
allowed = true;
break;
}
}
if (!allowed) {
event.preventDefault();
if (Authentication.user !== undefined && typeof Authentication.user === 'object') {
$state.transitionTo('forbidden');
} else {
$state.go('authentication.signin').then(function () {
// Record previous state
storePreviousState(toState, toParams);
});
}
}
}
}

...tho it looks like it's already doing something like that using roles from route configs (e.g. https://github.com/meanjs/mean/blob/master/modules/chat/client/config/chat.client.routes.js#L18)

@lirantal lirantal self-assigned this Sep 6, 2016
@lirantal lirantal added this to the 0.5.0 milestone Sep 6, 2016
@lirantal lirantal closed this as completed Sep 6, 2016
@hyperreality
Copy link
Contributor

Fixed #1496

Gotta hate Javascript sometimes ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants