-
Notifications
You must be signed in to change notification settings - Fork 36
/
SignUp.js
87 lines (85 loc) · 2.3 KB
/
SignUp.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
import React from 'react';
import { TextInput, Button, StyleSheet, Text, View } from 'react-native';
import { Auth } from 'aws-amplify';
export default class App extends React.Component {
state = {
username: '',
password: '',
phone_number: '',
email: '',
confirmationCode: '',
};
onChangeText(key, value) {
this.setState({
[key]: value,
});
}
signUp() {
Auth.signUp({
username: this.state.username,
password: this.state.password,
attributes: {
email: this.state.email,
phone_number: this.state.phone_number,
},
})
.then(() => console.log('successful sign up!'))
.catch(err => console.log('error signing up!: ', err));
}
confirmSignUp() {
Auth.confirmSignUp(this.state.username, this.state.confirmationCode)
.then(() => console.log('successful confirm sign up!'))
.catch(err => console.log('error confirming signing up!: ', err));
}
render() {
return (
<View style={styles.container}>
<TextInput
onChangeText={value => this.onChangeText('username', value)}
style={styles.input}
placeholder="username"
/>
<TextInput
onChangeText={value => this.onChangeText('password', value)}
style={styles.input}
secureTextEntry={true}
placeholder="password"
/>
<TextInput
onChangeText={value => this.onChangeText('phone_number', value)}
style={styles.input}
placeholder="phone"
/>
<TextInput
onChangeText={value => this.onChangeText('email', value)}
style={styles.input}
placeholder="email"
/>
<Button title="Sign Up" onPress={this.signUp.bind(this)} />
<TextInput
onChangeText={value => this.onChangeText('confirmationCode', value)}
style={styles.input}
placeholder="confirmation Code"
/>
<Button
title="Confirm Sign Up"
onPress={this.confirmSignUp.bind(this)}
/>
</View>
);
}
}
const styles = StyleSheet.create({
input: {
height: 50,
borderBottomWidth: 2,
borderBottomColor: '#2196F3',
margin: 10,
},
container: {
flex: 1,
backgroundColor: '#fff',
justifyContent: 'center',
padding: 16,
},
});