-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
58 lines (45 loc) · 1.31 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
/*
This file is the main file that runs the app.
Most functionality is distibuted to navigation.
*/
import React from 'react';
import { AsyncStorage, } from 'react-native';
import AppNavigation from './App/Navigation/AppNavigation';
import LoginScreen from './App/Screens/LoginScreen';
import firebase from 'firebase';
import {firestore, storage} from './firebase.js'
export default class App extends React.Component {
constructor(props) {
super(props);
//MAKE SURE LOGGED IN STATE IS FALSE WHEN DONE WITH APP
this.state = {
loggedIn: false,
unsubscribe: null,
user: null,
}
}
// Check out this link to learn more about firebase.auth()
// https://firebase.google.com/docs/reference/node/firebase.auth.Auth
componentDidMount() {
//sign out implemented elsewhere - check the navigation tab
// This auto detects whether or not a user is signed in.
let unsubscribe = firebase.auth().onAuthStateChanged((user) => {
if (user) {
this.setState({ loggedIn: true });
} else {
this.setState({ loggedIn: false });
}
});
this.setState({ unsubscribe });
}
componentWillUnmount() {
this.state.unsubscribe();
}
render() {
if (this.state.loggedIn) {
return<AppNavigation />
} else {
return <LoginScreen />
}
}
}