-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
91 lines (81 loc) · 1.87 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
import firebase from "firebase";
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import {
Header,
Button,
Card,
CardSection,
Spinner
} from "./src/components/common";
import LoginForm from "./src/components/LoginForm";
export default class App extends React.Component {
state = {
loggedIn: null
};
componentDidMount() {
// Initialize Firebase
var config = {
apiKey: "AIzaSyA34iXC2j8f4lsZiKWBA6Hl3VnoBAxK2KM",
authDomain: "authentication-d111f.firebaseapp.com",
databaseURL: "https://authentication-d111f.firebaseio.com",
projectId: "authentication-d111f",
storageBucket: "authentication-d111f.appspot.com",
messagingSenderId: "437974671853"
};
firebase.initializeApp(config);
firebase.auth().onAuthStateChanged(user => {
console.log("user", user);
if (user) {
this.setState({
loggedIn: true
});
} else {
this.setState({
loggedIn: false
});
}
});
}
logOut = () => {
firebase.auth().signOut();
};
renderContent = () => {
switch (this.state.loggedIn) {
case true:
return (
<Card>
<CardSection>
<Button onClick={this.logOut}>Log Out</Button>
</CardSection>
</Card>
);
case false:
return <LoginForm />;
default:
return (
<Card>
<CardSection>
<Spinner />
</CardSection>
</Card>
);
}
};
render() {
return (
<View style={styles.container}>
<Header headerText="Authentication" />
{this.renderContent()}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
// flex: 1,
// backgroundColor: "#fff",
// alignItems: "center",
// justifyContent: "center"
}
});