diff --git a/app/components/Auth.js b/app/components/Auth.js
index 81388c01..e677673a 100644
--- a/app/components/Auth.js
+++ b/app/components/Auth.js
@@ -1,33 +1,34 @@
// @flow
import * as React from 'react';
-import { Provider } from 'mobx-react';
+import { Provider, observer, inject } from 'mobx-react';
import stores from 'stores';
+import AuthStore from 'stores/AuthStore';
import ApiKeysStore from 'stores/ApiKeysStore';
import UsersStore from 'stores/UsersStore';
import CollectionsStore from 'stores/CollectionsStore';
import IntegrationsStore from 'stores/IntegrationsStore';
import CacheStore from 'stores/CacheStore';
+import LoadingIndicator from 'components/LoadingIndicator';
type Props = {
+ auth: AuthStore,
children?: React.Node,
};
let authenticatedStores;
-const Auth = ({ children }: Props) => {
- if (stores.auth.authenticated) {
- stores.auth.fetch();
+const Auth = observer(({ auth, children }: Props) => {
+ if (auth.authenticated) {
+ const { user, team } = auth;
- // TODO: Show loading state
- if (!stores.auth.team || !stores.auth.user) {
- return null;
+ if (!team || !user) {
+ return ;
}
// Only initialize stores once. Kept in global scope because otherwise they
// will get overridden on route change
if (!authenticatedStores) {
// Stores for authenticated user
- const { user, team } = stores.auth;
const cache = new CacheStore(user.id);
authenticatedStores = {
integrations: new IntegrationsStore(),
@@ -55,8 +56,8 @@ const Auth = ({ children }: Props) => {
return {children};
}
- stores.auth.logout();
+ auth.logout();
return null;
-};
+});
-export default Auth;
+export default inject('auth')(Auth);
diff --git a/app/stores/AuthStore.js b/app/stores/AuthStore.js
index c1f10559..9cc55d23 100644
--- a/app/stores/AuthStore.js
+++ b/app/stores/AuthStore.js
@@ -58,7 +58,9 @@ class AuthStore {
Cookie.remove('accessToken', { path: '/' });
await localForage.clear();
- window.location.href = BASE_URL;
+
+ // add a timestamp to force reload from server
+ window.location.href = `${BASE_URL}?done=${new Date().getTime()}`;
};
@action
@@ -127,6 +129,8 @@ class AuthStore {
// sessions created pre-google auth
this.token = Cookie.get('accessToken') || data.token;
+ if (this.token) setImmediate(() => this.fetch());
+
autorun(() => {
try {
localStorage.setItem(AUTH_STORE, this.asJson);