-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
124 lines (115 loc) · 3.66 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { useEffect, useState } from "react";
import { View, StatusBar } from "react-native";
import { initializeApp } from "firebase/app";
import { initializeAuth } from "firebase/auth";
import { NavigationContainer } from "@react-navigation/native";
import { StripeProvider } from "@stripe/stripe-react-native";
import { FjallaOne_400Regular } from "@expo-google-fonts/dev";
import * as SplashScreen from "expo-splash-screen";
import HomeNavigator from "./components/HomeNavigator";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import FunnelStack from "./screens/FunnelStack/FunnelStack";
import LoginStack from "./screens/LoginStack/LoginStack";
import axios from "axios";
import * as Font from "expo-font";
import {
REACT_APP_FIREBASE_API_KEY,
REACT_APP_FIREBASE_AUTH_DOMAIN,
REACT_APP_FIREBASE_PROJECT_ID,
REACT_APP_FIREBASE_STORAGE_BUCKET,
REACT_APP_FIREBASE_MESSAGE_SENDER_ID,
REACT_APP_FIREBASE_APP_ID,
REACT_APP_FIREBASE_MEAUSUREMENT_ID,
REACT_APP_PUMPT_API_URL,
} from "@env";
import { colors } from "./styles";
const firebaseConfig = {
apiKey: REACT_APP_FIREBASE_API_KEY,
authDomain: REACT_APP_FIREBASE_AUTH_DOMAIN,
projectId: REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: REACT_APP_FIREBASE_MESSAGE_SENDER_ID,
appId: REACT_APP_FIREBASE_APP_ID,
measurementId: REACT_APP_FIREBASE_MEAUSUREMENT_ID,
};
const app = initializeApp(firebaseConfig);
const auth = initializeAuth(app);
SplashScreen.preventAutoHideAsync();
const Stack = createNativeStackNavigator();
export default function App() {
const [loggedIn, setLoggedIn] = useState(false);
const [publishableKey, setPublishableKey] = useState();
const [appIsReady, setAppIsReady] = useState(false);
useEffect(() => {
(async () => {
try {
await Font.loadAsync({ FjallaOne_400Regular });
} catch {
console.log("error loading fonts in CustomInput");
}
})();
try {
const fetchPublishableKey = async () => {
await axios
.get(`${REACT_APP_PUMPT_API_URL}/get-publishable-key`)
.then((res) => {
setPublishableKey(res.data.publishableKey);
})
.catch((error) => {
console.log(`error in useEffectPublishableKey: ${error}`);
});
};
fetchPublishableKey();
} catch (e) {
console.warn(e);
} finally {
// Tell the application to render
setAppIsReady(true);
}
const unsubscribe = auth.onAuthStateChanged((user) => {
if (user && auth.currentUser?.emailVerified) setLoggedIn(true);
else setLoggedIn(false);
});
return unsubscribe;
}, []);
const onLayout = async () => {
if (appIsReady) await SplashScreen.hideAsync();
};
if (!appIsReady) {
return null;
}
return (
<View
style={{
flex: 1,
backgroundColor: colors.backgroundColor,
}}
onLayout={onLayout}
>
<StatusBar barStyle="light-content" />
{loggedIn && (
<StripeProvider publishableKey={publishableKey}>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home Navigator"
component={HomeNavigator}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Funnel Stack"
component={FunnelStack}
options={{ headerShown: false }}
/>
</Stack.Navigator>
</NavigationContainer>
</StripeProvider>
)}
{!loggedIn && (
<NavigationContainer>
<LoginStack />
</NavigationContainer>
)}
</View>
);
}