-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
82 lines (72 loc) · 2.52 KB
/
App.tsx
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
import { StatusBar } from 'expo-status-bar';
import React, { Component, useEffect, useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { background, neutral, text } from './styles/colors/theme';
import { createStackNavigator } from '@react-navigation/stack';
import { NavigationContainer } from '@react-navigation/native';
import Register from './components/auth/Register';
import Login from './components/auth/Login';
import Home from './components/Home';
import firebase from 'firebase';
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));
const firebaseConfig = {
apiKey: "AIzaSyBXG-glKkZqSh0J9KoBIEG2ulKBPbTx3PI",
authDomain: "taskr-5e166.firebaseapp.com",
projectId: "taskr-5e166",
storageBucket: "taskr-5e166.appspot.com",
messagingSenderId: "320325177286",
appId: "1:320325177286:web:1bfc3ce5a0d9a1e0c7ecc7",
measurementId: "G-FHWH5001ZX"
};
if (firebase.apps.length === 0) {
firebase.initializeApp(firebaseConfig);
}
const Stack = createStackNavigator()
export function App() {
const [loaded, setLoaded] = useState(false);
const [loggedIn, setLoggedIn] = useState(false);
useEffect(() => {
firebase.auth().onAuthStateChanged((user) => {
if (!user) {
setLoaded(true);
setLoggedIn(false);
} else {
setLoaded(true);
setLoggedIn(true);
}
})
})
if (!loaded) {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: "#21252F" }}>
<Text style={{ color: "#AFB4BB" }}>Loading</Text>
</View>
)
}
if (!loggedIn) {
return (
<NavigationContainer>
<StatusBar style="light" />
<Stack.Navigator initialRouteName="Login" screenOptions={{ cardStyle: { ...background.theme[800] } }}>
<Stack.Screen component={Register} name='Register' options={{ headerShown: false }} />
<Stack.Screen component={Login} name='Login' options={{ headerShown: false }} />
</Stack.Navigator>
</NavigationContainer>
);
}
return (
<Provider store={store}>
<NavigationContainer>
<StatusBar style="light" />
<Stack.Navigator initialRouteName="Home">
<Stack.Screen component={Home} name='Home' options={{ headerShown: false }} />
</Stack.Navigator>
</NavigationContainer>
</Provider>
)
}
export default App