Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android side not working and same code is working for IOS in react native #108

Open
GimmeForeDev1 opened this issue Jun 30, 2022 · 5 comments

Comments

@GimmeForeDev1
Copy link

GimmeForeDev1 commented Jun 30, 2022

I am working in React native , when User sign up in android side at that time i'm getting catch block with error of "User not found" but when i sign up via IOS device i am not getting error and successfully sign up and chatting with user .
Please give some solution for this

@DaveLomber
Copy link
Contributor

Can you post a code snippet how you do a login

@GimmeForeDev1
Copy link
Author

GimmeForeDev1 commented Jul 1, 2022 via email

@GimmeForeDev1
Copy link
Author

GimmeForeDev1 commented Jul 1, 2022 via email

@GimmeForeDev1
Copy link
Author

GimmeForeDev1 commented Jul 1, 2022

Hello ,
Please find below code which we have implemented in React native

--> Signup.js

  • Called this function on signup button

const User_signup_connectycube = (data) => {
console.log("data signup chat" , data )
const userProfile = {
password: ConnectyCubeConstent.Password,
email: data.email,
login: data.email,
};
console.log("chat ==>" , userProfile)
ConnectyCube.createSession()
.then((session) => {
ConnectyCube.users
.signup({ ...userProfile, ...session })
.then(async (user) => {
console.log("user connectyCube", user)
await AsyncStorage.setItem('ConnectyCubeUser', JSON.stringify(user));
})
})
.catch((error) => {
console.log("catch in complete profile" , error)
});
}

--> login.js

Called this event on press of login button
EventRegister.emitEvent(EventsNames.USER_LOGIN, "user login"); // send event to app.js to start updating location

--> App.js

componentDidMount() {
setTimeout(() => SplashScreen.hide() , 300);

EventRegister.addEventListener(EventsNames.USER_LOGIN, (data) => {
  console.log("EventRegister.addEventListener(EventsNames.USER_LOGIN, (data) => {");
  this.initalizeConnectyCube();

});
 this.AppStateChangeSubscription = AppState.addEventListener("change", this._handleAppStateChange);
}

 async initalizeConnectyCube() {
console.log("async initalizeConnectyCube() {");
// await this.checkPermission();

const {CREDENTIALS,CONFIG,Password} = ConnectyCubeConstent;
ConnectyCube.init(CREDENTIALS,CONFIG);

const login = await AsyncStorage.getItem('ConnectyCubeUser').then((u) => {
  //return JSON.parse(u).user.email
  console.log("user object " , u)
  console.log( {ConnectyCubeUser:u})
  console.log(typeof u)
  return JSON.parse(u)?.user?.email || JSON.parse(u)?.email 
});

console.log("user app" , await AsyncStorage.getItem('ConnectyCubeUser'));

const userCredentials = {
  login: this.state.userEmail,
  password: Password,
};

await ConnectyCube.createSession(userCredentials)
  .then((session) => {
    console.log("session" ,session)
    // SessionManager.setConnectyCubeUserSession(session);
    const userLoginCredentials = {
      email: this.state.userEmail,
      password: Password,
    };
    console.log("createSession -> ",session)
    return ConnectyCube.login(userLoginCredentials);
  })
  .then(async (user) => {
    console.log("login -> ",user)

    // await this.createPushListener();
     await this.subscribeToPushNotification();
    return ConnectyCube.chat.connect({
      userId: user.id,
      password: Password,
    });
  })
  // .then(this.userProfileUpdate)
  .catch((e)=>{
    console.log(".catch((e)=>{"+String(e));
  });

}

--> Orderlist.js

componentDidMount = () => {
this.focusListener = this.props.navigation.addListener( 'didFocus', payload => {
    this.setState({ curr_index: 0, orderType: "current", arrCurrData: [], arrPastData: [], page: 1 ,statusBarStyle: "dark-content"}, () => {
      this.apiCallMy_order_list(),
        this._retrieveData()
    })
    console.log("Type ===>",typeof ConnectyCube.users)
    // if(typeof ConnectyCube.users === "undefined") {
      EventRegister.emitEvent(EventsNames.USER_LOGIN, "user login"); // send event to app.js to start updating location
    // }
    this.setState({ statusBarStyle: "dark-content" })
  }
);

}

below is the code we do on press of the chat icon

onPress={() => {

          this.setState({isLoading : true})

          const searchParams = { email: item.user_email };
          if(typeof ConnectyCube.users === "undefined")
          {
            EventRegister.emitEvent(EventsNames.USER_LOGIN, "user login"); // send event to app.js to start updating location
          }
          else {

          ConnectyCube.users
            .get(searchParams)
            .then((result) => {
              
              const params = {
                type: 3,
                occupants_ids: [result.user.id],
              };
              
              ConnectyCube.chat.dialog
                .create(params)
                .then((dialog) => {
                  this.setState({isLoading : false} , () => {
                    this.props.navigation.navigate('OrderChat',{
                      name : item.name,
                      customer_notificationId : item.user_id,
                      chat_user_id : result.user.id,
                      dialog:dialog
                    })
                  })
                 
                })
                .catch((error) => {});
              
            })
            .catch((error) => {
              
            });

          }

        }}
        
 Thanks
 Jigar 

@DaveLomber
Copy link
Contributor

@GimmeForeDev1 looks good

can you do the following

1 - enable logs https://developers.connectycube.com/reactnative/?id=configuration

const CONFIG = {
  debug: { mode: 1 } // enable DEBUG mode (mode 0 is logs off, mode 1 -> console.log())
};
ConnectyCube.init(CREDENTIALS, CONFIG);

2 - try to login on iOS and reproduce the issue.
Then collect all the logs from console and share there

we should find a root cause there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants