forked from QuangNguyen1412/rn-air-monitor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
61 lines (58 loc) · 1.49 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
/**
* @file: App.js
*
* @summary
* Load Login page in ./src/components/screens/Login/Login at the beginning
*
* @author: Quang Nguyen
*
*/
import 'react-native-gesture-handler';
import React from 'react';
import Login from './src/components/screens/Login/Login';
import HomeScreen from './src/components/screens/Home/HomeScreen';
import firebase from 'react-native-firebase';
// import {createAppContainer} from 'react-navigation';
// import {createStackNavigator} from 'react-navigation-stack';
export const themeColor = {
bright: '#C5FBD0',
dark: '#325C3C',
error: '#ff0000',
};
global.email = "";
export default class App extends React.Component {
constructor() {
super();
this.state = {
loading: true,
};
}
/**
* When the App component mounts, we listen for any authentication
* state changes in Firebase.
* Once subscribed, the 'user' parameter will either be null
* (logged out) or an Object (logged in)
*/
componentDidMount() {
this.authSubscription = firebase.auth().onAuthStateChanged(user => {
this.setState({
loading: false,
user,
});
});
}
componentWillUnmount() {
this.authSubscription();
}
render() {
// console.log('User info ', this.state.user);
// return <HomeScreen />;
if (this.state.user == null) {
return <Login />;
} else {
console.log('Logged in with user ' + this.state.user.email);
global.email = this.state.user.email;
return <HomeScreen />;
}
}
}