Guest User

Untitled

a guest
Feb 19th, 2018
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 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 './src/aws-exports'
  12. Amplify.configure(config)
  13.  
  14. type Props = {};
  15. export default class App extends Component<Props> {
  16. state = {
  17. authCode: '',
  18. user: {}
  19. }
  20. onChangeText(authCode) {
  21. this.setState({ authCode })
  22. }
  23. signUp() {
  24. Auth.signUp({
  25. username: 'dabit3',
  26. password: 'MyCoolP@ssw0rd1!',
  27. attributes: {
  28. phone_number: '+16018127241',
  29. email: 'dabit3@gmail.com'
  30. }
  31. })
  32. .then(res => {
  33. console.log('successful signup: ', res)
  34. })
  35. .catch(err => {
  36. console.log('error signing up: ', err)
  37. })
  38. }
  39. confirmUser() {
  40. const { authCode } = this.state
  41. Auth.confirmSignUp('dabit3', authCode)
  42. .then(res => {
  43. console.log('successful confirmation: ', res)
  44. })
  45. .catch(err => {
  46. console.log('error confirming user: ', err)
  47. })
  48. }
  49. signIn() {
  50. Auth.signIn(username, password)
  51. .then(user => {
  52. this.setState({ user })
  53. })
  54. .catch(err => {
  55. console.log('error signing in: ', err)
  56. })
  57. }
  58. confirmSignIn() {
  59. Auth.confirmSignIn(user, authCode)
  60. .then(user => {
  61. console.log('user: ', user)
  62. }).catch(err => {
  63. console.log('error confirming sign in: ', err)
  64. })
  65. }
  66. render() {
  67. return (
  68. <View style={styles.container}>
  69. <Button title='Sign Up' onPress={this.signUp.bind(this)} />
  70. <TextInput
  71. placeholder='Input Code'
  72. onChangeText={value => this.onChangeText(value)}
  73. style={styles.input}
  74. />
  75. <Button
  76. title='Confirm User'
  77. onPress={this.confirmUser.bind(this)}
  78. />
  79. </View>
  80. );
  81. }
  82. }
  83.  
  84. const styles = StyleSheet.create({
  85. input: {
  86. height: 50,
  87. backgroundColor: '#ededed',
  88. marginVertical: 10
  89. },
  90. container: {
  91. flex: 1,
  92. justifyContent: 'center',
  93. backgroundColor: '#F5FCFF'
  94. }
  95. });
Add Comment
Please, Sign In to add comment