-
Notifications
You must be signed in to change notification settings - Fork 0
/
signin.js
86 lines (77 loc) · 1.92 KB
/
signin.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
'use strict';
import React, {
StyleSheet,
Text,
View,
Navigator,
TextInput,
} from 'react-native';
import Firebase from 'firebase';
import Button from './button.js';
const auth = new Firebase("https://<URL>.firebaseIO.com");
export default React.createClass({
getInitialState() {
return {
email: '',
password: '',
errorMessage: ''
};
},
render() {
return (
<View style={styles.container}>
<Text>Sign In</Text>
<Text style={styles.label}>Email:</Text>
<TextInput
value={this.state.email}
onChangeText={(text) => this.setState({email: text})}
style={styles.input} />
<Text style={styles.label}>Password:</Text>
<TextInput
secureTextEntry={true}
value={this.state.password}
onChangeText={(text) => this.setState({password: text})}
style={styles.input} />
<Text style={styles.label}>{this.state.errorMessage}</Text>
<Button text={'Signin'} onPress={this.onSignInPress} />
<Button text={'Create account...'} onPress={this.onSignUpPress} />
</View>
);
},
onSignInPress() {
auth.authWithPassword({
email : this.state.email,
password : this.state.password
}, (error, authData) => {
if (error) {
this.setState({errorMessage: error.message});
} else {
this.props.navigator.immediatelyResetRouteStack([{name: 'dashboard'}]);
}
});
},
onSignUpPress() {
this.props.navigator.push({name: 'signup'})
}
});
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white'
},
label: {
fontSize: 18
},
input: {
padding: 4,
height: 40,
borderColor: 'gray',
borderWidth: 1,
borderRadius: 5,
margin: 5,
width: 200,
alignSelf: 'center'
}
});