-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
103 lines (85 loc) · 2.72 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { StatusBar } from 'expo-status-bar';
import React, { Component} from 'react';
import { View, Text } from 'react-native'
import * as firebase from 'firebase'
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import LandingScreen from './components/auth/Landing'
import RegisterScreen from './components/auth/Register'
import LoginScreen from './components/auth/Login'
import MainScreen from './components/Main'
import AddScreen from './components/main/Add'
import { Provider } from 'react-redux'
import { createStore, applyMiddleware } from 'redux'
import rootReducer from './redux/reducers'
import thunk from 'redux-thunk'
const store = createStore(rootReducer, applyMiddleware(thunk))
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyCyddOcvyr1WoygBIRUsMbtFr2xWvNfeOc",
authDomain: "instagram-dev-116bb.firebaseapp.com",
projectId: "instagram-dev-116bb",
storageBucket: "instagram-dev-116bb.appspot.com",
messagingSenderId: "205084692978",
appId: "1:205084692978:web:1976562e5fc4b4e5521b6b",
measurementId: "G-EJHMSEFW84"
};
if (firebase.apps.length === 0) {
firebase.initializeApp(firebaseConfig)
}
const Stack = createStackNavigator();
export class App extends Component {
constructor(props){
super()
this.state ={
loaded: false,
}
}
componentDidMount(){
firebase.auth().onAuthStateChanged((user) => {
if(!user){
this.setState({
loggedIn: false,
loaded: true,
})
}else{
this.setState({
loggedIn: true,
loaded: true,
})
}
})
}
render() {
const { loggedIn, loaded } = this.state;
if(!loaded){
return(
<View style={{ flex: 1, justifyContent: 'center' }}>
<Text>Loading</Text>
</View>
)
}
if(!loggedIn){
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Landing">
<Stack.Screen name="Landing" component={LandingScreen} options={{ headerShown: false}} />
<Stack.Screen name="Register" component={RegisterScreen} />
<Stack.Screen name="Login" componen={LoginScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
return(
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator initialRouteName="Main">
<Stack.Screen name="Main" component={MainScreen} options={{ headerShown: false}} />
<Stack.Screen name="Add" component={AddScreen} />
</Stack.Navigator>
</NavigationContainer>
</Provider>
)
}
}
export default App