-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
51 lines (47 loc) · 1.46 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React, { Component } from 'react';
import firebase from 'firebase';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import SplashScreen from 'react-native-splash-screen'
import { NavigationActions } from 'react-navigation';
import reducers from './src/reducers';
import { configFirebase } from './src/util';
import ReduxNavigation from './src/navigation/ReduxNavigation';
import { INIT_AUTH } from './src/actions/types';
export default class App extends Component {
componentWillMount() {
firebase.initializeApp(configFirebase);
}
/**
* check to see if the user has signed in already or not
*/
initAuth(dispatch) {
return new Promise((resolve, reject) => {
const unsubscribe = firebase.auth().onAuthStateChanged(
authUser => {
dispatch({ type: INIT_AUTH, payload: authUser });
unsubscribe();
resolve(authUser);
},
error => reject(error)
);
});
}
render() {
const store = createStore(reducers, {}, applyMiddleware(thunk));
this.initAuth(store.dispatch)
.then(authUser => {
if(authUser) {
store.dispatch(NavigationActions.navigate({routeName: 'drawerStack'}));
}
SplashScreen.hide();
})
.catch(error => {SplashScreen.hide(); console.error(error)});
return (
<Provider store={store}>
<ReduxNavigation />
</Provider>
);
}
}