This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
/
SignUp.js
104 lines (100 loc) · 2.55 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React, { Fragment, Component } from 'react'
import { View, StyleSheet } from 'react-native'
import { Input, ActionButton } from '../../components'
import { Auth } from 'aws-amplify'
class SignIn extends Component {
state = {
username: '',
password: '',
email: '',
phone_number: '',
authCode: '',
stage: 0
}
onChangeText = (key, value) => {
this.setState({ [key]: value })
}
signUp = async () => {
const {
username, password, email, phone_number
} = this.state
try {
await Auth.signUp({ username, password, attributes: { email, phone_number }})
console.log('successful sign up..')
this.setState({ stage: 1 })
} catch (err) {
console.log('error signing up...', err)
}
}
confirmSignUp = async () => {
const { username, authCode } = this.state
try {
await Auth.confirmSignUp(username, authCode)
this.props.toggleAuthType('showSignIn')
} catch (err) {
console.log('error signing up...', err)
}
}
render() {
return (
<View style={styles.container}>
{
this.state.stage === Number(0) && (
<Fragment>
<Input
placeholder='Username'
type='username'
onChangeText={this.onChangeText}
/>
<Input
placeholder='Password'
type='password'
onChangeText={this.onChangeText}
secureTextEntry
/>
<Input
placeholder='Email'
type='email'
onChangeText={this.onChangeText}
/>
<Input
placeholder='Phone Number'
type='phone_number'
onChangeText={this.onChangeText}
/>
<ActionButton
title='Sign Up'
onPress={this.signUp}
/>
</Fragment>
)
}
{
this.state.stage === Number(1) && (
<Fragment>
<Input
placeholder='Confirmation Code'
type='authCode'
onChangeText={this.onChangeText}
/>
<ActionButton
title='Confirm Sign Up'
onPress={this.confirmSignUp}
/>
</Fragment>
)
}
</View>
)
}
}
const styles = StyleSheet.create({
container: {
},
input: {
backgroundColor: '#fcf3db',
borderRadius: 30,
height: 45
}
})
export default SignIn