Make sure session is loaded before route is rendered

This commit is contained in:
Arik Fraimovich
2016-11-27 14:02:29 +02:00
parent 724b7675c7
commit 51528508ba
2 changed files with 22 additions and 15 deletions

View File

@@ -1,17 +1,18 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<base href="/">
<title>Redash</title>
<head lang="en">
<meta charset="UTF-8">
<base href="/">
<title>Redash</title>
<link rel="icon" type="image/png" sizes="32x32" href="./assets/images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="./assets/images/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="./assets/images/favicon-16x16.png">
</head>
<body ng-app="app">
<section>
<div ng-view></div>
</section>
</body>
<link rel="icon" type="image/png" sizes="32x32" href="./assets/images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="./assets/images/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="./assets/images/favicon-16x16.png">
</head>
<body ng-app="app">
<section>
<div ng-view></div>
</section>
</body>
</html>

View File

@@ -116,10 +116,16 @@ ngModule.config(($routeProvider,
});
});
ngModule.run(($location, $rootScope, Auth) => {
ngModule.run(($location, $rootScope, $route, Auth) => {
$rootScope.$on('$routeChangeStart', (event, to) => {
if (!Auth.isAuthenticated()) {
console.log('need to login', to);
event.preventDefault();
// maybe we only miss the session? try to load session
Auth.loadSession().then(() => {
$route.reload();
}).catch(() => {
Auth.login();
});
}
});
});