I want to allow some users to enter a route and others dont.
I used simple auth for authentication and it will load the user data with a promise. Th Problem is that willTransition() does not wait until my user is loaded so it will show the index route before I can check if the user have access to it.
So in router.js I have:
willTransition(oldRoute, nextRoute, transition) {
return this.get('session').authenticate('authenticator:application').then(() => {
if(this.get('user.isAdmin')) return true
else alert('not allowed to enter')
})
}
This is just an example in real I have more like user.isCat and cat are allowed to enter /cats and /cute routes.
I know that I can check user.isAdmin also in beforeModel() of the route but I have many other routes and permission groups, so I want to have a single place in the router to manage that
Aucun commentaire:
Enregistrer un commentaire