-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
87 lines (79 loc) · 2.1 KB
/
App.js
File metadata and controls
87 lines (79 loc) · 2.1 KB
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
import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import * as firebase from "firebase";
import {AppLoading} from 'expo';
import Navigator from './navigation/Navigator'
import LoginScreen from './pages/LoginScreen'
export default class App extends Component {
constructor(props){
super(props)
this.state={
login_status: -1,
new_user: false
}
}
setNewDisplayName(name){
this.setState({displayname: name, new_user: true})
}
componentDidMount() {
var config = {
apiKey: "AIzaSyByWpAy1yK5XrD5ENlXEIIsC5VxQOxLY7A",
authDomain: "mta-scanner.firebaseapp.com",
databaseURL: "https://mta-scanner.firebaseio.com",
projectId: "mta-scanner",
storageBucket: "mta-scanner.appspot.com",
messagingSenderId: "1081675998683"
};
firebase.initializeApp(config);
firebase.auth().onAuthStateChanged((user) => {
if (user) {
if (this.state.new_user){
this.writeUserData(this.state.displayname, user.uid);
user.updateProfile({
displayName: this.state.displayname,
}).then(()=>{
console.log("Display Name Set To: " + user.displayName)
});
this.setState({new_user: false})
}
this.setState({login_status: 1})
}else{
this.setState({login_status: 0})
}
})
}
writeUserData(usersName, userID) {
firebase.database().ref('users/' + userID).set({
name: usersName,
balance: 0,
time: "none",
expiration: "none",
transactions : {
0: "No transactions"
}
})
}
render() {
if (this.state.login_status == 0){
return(
<LoginScreen updateName={this.setNewDisplayName.bind(this)}/>
)
}else if (this.state.login_status == 1){
return(
<Navigator />
)
}else{
return(
<AppLoading/>
)
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});