Reputation: 756
I have followed the following steps in order to get Amplify Auth login flow working on React Native:
The React Native app that I am running consists of a main App.js component with the following imports:
import React, { Component } from "react";
import { StyleSheet, View, Text } from "react-native";
import Amplify, { Auth } from "aws-amplify";
import AWSConfig from "./aws-exports";
Amplify.configure(AWSConfig);
import Tabs from "./Tabs";
My main App.js file also has two tabs (one for SignIn component and another for SignUp component).
My SignUp component looks like this:
...
signUp = () => {
Auth.signUp({
username: this.state.username,
password: this.state.password,
attributes: {
email: this.state.email
}
})
.then(() => console.warn("successful sign up!"))
.catch(err => console.warn("error signing up!: ", err));
};
confirmSignUp = () => {
Auth.confirmSignUp(this.state.username, this.state.confirmationCode)
.then(() => console.warn("successful confirm sign up!"))
.catch(err => console.warn("error confirming signing up!: ", err));
};
render() {
return (
<View style={styles.container}>
...
<Button title="Confirm Sign Up" onPress={this.confirmSignUp} />
</View>
);
}
...
My problem is that when I try to sign up a user then I get:
attribute value for phone number must not be null
When I check the attributes of the User Pool that was automatically created at: AWS cognito console then
is the only "standard attribute that is required".
Please advise.
Upvotes: 1
Views: 1648
Reputation: 21
You can do something like this: In your component class initialise state to remember the 'email_address' and 'phone_number' inputs, and make sure to set the "onChange" function of the textInput to "this.setState({phone_number: value})"
`class myClass extends React.component{
constructor(props){
super(props)
this.state={(email_address = undefined;
phone_number= undefined;)}
}
... //Same code here
signUp = () => {
Auth.signUp({
username: this.state.username,
password: this.state.password,
attributes: {
email: this.state.email
phone_number: this.state.phone_number
}
})
.then(() => console.warn("successful sign up!"))
.catch(err => console.warn("error signing up!: ", err));
};
....//Some code
}`
Upvotes: 0