Guest User

Untitled

a guest
Mar 10th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. StyleSheet,
  4. Text,
  5. Button,
  6. TextInput,
  7. View
  8. } from 'react-native';
  9.  
  10. import Amplify, { Auth } from 'aws-amplify'
  11. import config from './aws-exports'
  12. Amplify.configure(config)
  13.  
  14. export default class App extends Component {
  15. state = {
  16. username: '',
  17. email: '',
  18. phone_number: '',
  19. password: '',
  20. authCode: ''
  21. }
  22. onChangeText = (key, value) => {
  23. this.setState({
  24. [key]: value
  25. })
  26. }
  27. signUp() {
  28. const { username, password, email, phone_number } = this.state
  29. Auth.signUp({
  30. username,
  31. password,
  32. attributes: {
  33. phone_number,
  34. email
  35. }
  36. })
  37. .then(() => console.log('user sign up success!!'))
  38. .catch(err => console.log('error signing up user: ', err))
  39. }
  40. confirmSignUp() {
  41. Auth.confirmSignUp(this.state.username, this.state.authCode)
  42. .then(() => console.log('confirm user sign up success!!'))
  43. .catch(err => console.log('error confirming signing up user: ', err))
  44. }
  45. render() {
  46. return (
  47. <View style={styles.container}>
  48. <TextInput
  49. style={styles.input}
  50. placeholder='Username'
  51. onChangeText={val => this.onChangeText('username', val)}
  52. />
  53. <TextInput
  54. style={styles.input}
  55. placeholder='Password'
  56. secureTextEntry={true}
  57. onChangeText={val => this.onChangeText('password', val)}
  58. />
  59. <TextInput
  60. style={styles.input}
  61. placeholder='Email'
  62. onChangeText={val => this.onChangeText('email', val)}
  63. />
  64. <TextInput
  65. style={styles.input}
  66. placeholder='Phone Number'
  67. onChangeText={val => this.onChangeText('phone_number', val)}
  68. />
  69. <Button
  70. title='Sign Up'
  71. onPress={this.signUp.bind(this)}
  72. />
  73. <TextInput
  74. style={styles.input}
  75. placeholder='Confirmation Code'
  76. onChangeText={val => this.onChangeText('authCode', val)}
  77. />
  78. <Button
  79. title='Confirm Sign Up'
  80. onPress={this.confirmSignUp.bind(this)}
  81. />
  82. </View>
  83. );
  84. }
  85. }
  86.  
  87. const styles = StyleSheet.create({
  88. container: {
  89. flex: 1,
  90. justifyContent: 'center',
  91. },
  92. input: {
  93. height: 50,
  94. borderBottomWidth: 2,
  95. borderBottomColor: '#9E9E9E',
  96. margin: 10
  97. }
  98. });
Add Comment
Please, Sign In to add comment