diff --git a/src/Expensify.js b/src/Expensify.js
index 650abb2a9abf7..370266fe262b4 100644
--- a/src/Expensify.js
+++ b/src/Expensify.js
@@ -1,4 +1,6 @@
import React, {Component} from 'react';
+import {View} from 'react-native';
+import get from 'lodash.get';
// import {Beforeunload} from 'react-beforeunload';
import SignInPage from './page/SignInPage';
@@ -8,6 +10,8 @@ import * as ActiveClientManager from './lib/ActiveClientManager';
import {verifyAuthToken} from './lib/actions/ActionsSession';
import IONKEYS from './IONKEYS';
import WithIon from './components/WithIon';
+import styles from './style/StyleSheet';
+
import {
Route,
Router,
@@ -23,6 +27,22 @@ class Expensify extends Component {
super(props);
this.recordCurrentRoute = this.recordCurrentRoute.bind(this);
+
+ this.state = {
+ loading: true,
+ authenticated: false,
+ };
+ }
+
+ componentDidMount() {
+ // We need to delay initializing the main app so we can check for an authToken and
+ // redirect to the signin page if we do not have one. Otherwise when the app inits
+ // we will fall through to the homepage and the user will see a brief flash of the main
+ // app experience.
+ Ion.get(IONKEYS.SESSION)
+ .then((response) => {
+ this.setState({loading: false, authenticated: Boolean(get(response, 'authToken', false))});
+ });
}
/**
@@ -35,13 +55,23 @@ class Expensify extends Component {
}
render() {
+ if (this.state.loading) {
+ return (
+
+ );
+ }
+
+ // We can only have a redirectTo if this is not the initial render so if we have one we'll
+ // always navigate to it. If we are not authenticated by this point then we'll force navigate to sign in.
+ const redirectTo = this.state.redirectTo || (!this.state.authenticated && '/signin');
+
return (
// TODO: Mobile does not support Beforeunload
//
{/* If there is ever a property for redirecting, we do the redirect here */}
- {this.state && this.state.redirectTo && }
+ {redirectTo && }
diff --git a/src/lib/Network.js b/src/lib/Network.js
index 4d19ed78d17a4..233b4b61c70e9 100644
--- a/src/lib/Network.js
+++ b/src/lib/Network.js
@@ -172,7 +172,7 @@ function request(command, data, type = 'post') {
})
.then(redirectToSignIn);
}
- return setSuccessfulSignInData(response, command.exitTo);
+ return setSuccessfulSignInData(response, data.exitTo);
})
.then((response) => {
// If Expensify login, it's the users first time signing in and we need to
diff --git a/src/style/StyleSheet.js b/src/style/StyleSheet.js
index ac4a434fcf835..e8f69dda85360 100644
--- a/src/style/StyleSheet.js
+++ b/src/style/StyleSheet.js
@@ -176,6 +176,10 @@ const styles = {
padding: 20,
},
+ genericView: {
+ backgroundColor: colors.heading,
+ },
+
signInPageInner: {
marginLeft: 'auto',
marginRight: 'auto',