-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
99 lines (83 loc) · 2.42 KB
/
App.js
File metadata and controls
99 lines (83 loc) · 2.42 KB
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
import React, { useState, useEffect } from "react";
import { StyleSheet } from "react-native";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { NavigationContainer } from '@react-navigation/native';
import { bgSecondary } from "./utils/colours";
import TabNavigator from "./components/navigation/TabNavigator";
import AuthNavigator from "./components/navigation/AuthNavigator";
import SplashScreen from "./components/SplashScreen";
// For redux and storage
import firebase from "firebase/app";
import { Provider } from "react-redux";
import { store } from "./redux/store";
import {
REACT_APP_API_KEY,
REACT_APP_AUTH_DOMAIN,
REACT_APP_DATABASE_URL,
REACT_APP_PROJECT_ID,
REACT_APP_STORAGE_BUCKET,
REACT_APP_MESSAGING_SENDER_ID,
REACT_APP_APP_ID
} from "@env";
const firebaseConfig = {
apiKey: REACT_APP_API_KEY,
authDomain: REACT_APP_AUTH_DOMAIN,
databaseURL: REACT_APP_DATABASE_URL,
projectId: REACT_APP_PROJECT_ID,
storageBucket: REACT_APP_STORAGE_BUCKET,
messagingSenderId: REACT_APP_MESSAGING_SENDER_ID,
appId: REACT_APP_APP_ID
};
// This checks that no other instance of firebase is running
if (firebase.apps.length === 0) {
firebase.initializeApp(firebaseConfig)
}
const App = () => {
const [isLoading, setIsLoading] = useState(true);
const [loggedIn, setLoggedIn] = useState(false);
useEffect(() => {
firebase.auth().onAuthStateChanged((user) => {
if(!user || (user == undefined)) {
setIsLoading(false)
setLoggedIn(false)
} else {
setIsLoading(false)
setLoggedIn(true)
}
})
}, [loggedIn])
if (isLoading) {
return (
<SafeAreaProvider style={styles.container}>
<SplashScreen />
</SafeAreaProvider>
)
}
return (
<Provider store={store}>
{
loggedIn
? (
<NavigationContainer>
<SafeAreaProvider style={styles.container}>
<TabNavigator />
</SafeAreaProvider>
</NavigationContainer>
) : (
<NavigationContainer>
<SafeAreaProvider style={styles.container}>
<AuthNavigator />
</SafeAreaProvider>
</NavigationContainer>
)
}
</Provider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: bgSecondary,
},
})
export default App;