Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async storeToken(accesstoken) {
- try {
- await AsyncStorage.setItem(AccessToken, accesstoken);
- } catch (error) {
- console.log('AsyncStorage error: ' + error.message);
- }
- }
- userRegister = () =>{
- const {username} = this.state;
- const {password} = this.state;
- if(username=="" || password==""){
- alert("Please fill out all fields");
- }
- // else if (password!=cpassword) {
- // alert("Passwords do not match.");
- // }
- else{
- fetch('http://192.168.01.1/test/register.php', {
- method: 'post',
- header:{
- 'Accept': 'application/json',
- 'Content-type': 'application/json'
- },
- body:JSON.stringify({
- username: username,
- password: password,
- })
- })
- .then((response) => response.json())
- .then((responseData) =>{
- // how to define accesstoken
- //this.storeToken('accessToken',JSON.stringify(results));
- //if using in this then same error
- this.storeToken('accesstoken',responseData.accesstoken)
- if(responseData == 'User Registered Successfully'){
- Alert.alert(
- 'Success',
- 'User Registered Successfully',
- [
- // {text:'ok', onPress: () => this.props.navigation.goBack() }
- ]
- );
- //this.props.navigation.goBack()
- }else{
- alert(responseJson);
- }
- })
- .catch((error)=>{
- console.log(error);
- });
- }
- }
Add Comment
Please, Sign In to add comment