forked from zuberrahman/Healthical
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
44 lines (35 loc) · 1.05 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
import React, { useState, useEffect, createContext } from 'react'
import * as firebase from 'firebase';
import apiKeys from './src/Config/firebaseConfig';
import AuthStack from './src/Navigation/AuthStack'
import HomeStack from './src/Navigation/HomeStack'
import { AuthContext } from "./src/Context/Context";
const App = () => {
if (!firebase.apps.length) {
console.log('Connected with Firebase')
firebase.initializeApp(apiKeys.firebaseConfig);
}
const [initializing, setInitializing] = useState(true)
const [user, setUser] = useState(null)
// Handle user state changes
function onAuthStateChanged(result) {
setUser(result)
if (initializing) setInitializing(false)
}
useEffect(() => {
const authSubscriber = firebase.auth().onAuthStateChanged(onAuthStateChanged)
// unsubscribe on unmount
return authSubscriber
}, [])
if (initializing) {
return null
}
return user ? (
<AuthContext.Provider value={user}>
<HomeStack />
</AuthContext.Provider>
) : (
<AuthStack />
)
};
export default App;