My current solution is based on routing. I have created submission and landing page views. When the user is on the login page and logs in, he is directed to the landing page. When the user is not authenticated and does not enter any path on the website, he is redirected to the login page.
here is the RouteInitializer:
..addRoute(
name: 'signin',
path: '/signin',
enter: view('view/signin.html'))
..addRoute(
name: 'dashboard',
path: '/dashboard',
defaultRoute: true,
preEnter: _ensureAuthenticated,
enter: view('view/dashboard.html'))
The method _ensureAuthenticated()should be set as a callback preEnterand evaluates the input status:
_ensureAuthenticated(RoutePreEnterEvent routeEvent) {
if (!_userService.loggedIn) {
routeEvent.allowEnter(new Future<bool>.value(false));
_router.go('signin', {});
}
}
While this works well, the method _ensureAuthenticated()should be set as a callback preEnterin each route. Is there a easier way to catch preEnterglobally? Installing it on the track rootdoes not work.
source
share