Need to use certain network to login

2.0.3

Sometimes, it is difficult to login. I have to change my network to another else. I am sure the speed is the same. It only happen in login function. Everything else is normal.

Hello @hilmyas
Can you please elaborate on the issue. Is it possible that the network you are not able to connect on is a secured network that is blocking connections to unknown URLs and maybe the CometChat URLs will have to be white-listed for that particular network.
Awaiting Reply

Cannot login to comet with exception:

Login failed with exception: No response received within reply timeout. Timeout was 15000ms (~15s). Used filter: No filter used or filter was ‘null’.

I think the internet is fine. How to make sure that my internet is blocking the API?

what can I help to resolve this problem?

I get error code recorded by firebase performance about requesting to api-us.cometchat.io/v2.0/users
error code 400 gets the highest number

Hello @hilmyas
Can you share the complete error logs so that we can investigate

the log shows only this message

2020-05-08 19:13:21.893 29681-29681/myApplicationPackage E/InputPinActivity$loginComet: Login failed with exception: No response received within reply timeout. Timeout was 15000ms (~15s). Used filter: No filter used or filter was ‘null’.

when I show firebase performance, it shows:

we can see that the highest error code is error code 400

wait, is the endpoint url of login provided in the firebase image right? correct me if I am wrong. so I can re-check it

is this the right endpoint apiclient-us.cometchat.io/v2.0/…?

Hi @hilmyas,

The methods createUser(user), updateUser(user) and login(UID, APIKEY, listener) use api-us.cometchat.io and rest of the SDK methods use apiclient-us.cometchat.io

The 400 Error code for the endpoint api-us.cometchat.io/v2.0/users implies that the validation of the post body params has failed. Please check the user object you are passing to the createUser method.

Feel free to let us know if you face any other issues.

Warm Regards,

Ketan Yekale
CometChat Pro

1 Like

Oh, OK. I found the problem in creating user, but how about login?

This is the step. Everytime users successfully login to my server, they do:

  1. Create a new user to comet chat -> regardless user already created -> return success/failed response (so fast)
  2. Login as comet user using
    CometChat.login(“their_id”,
    “apikey_auth”) -> doesn’t return anything but “Login failed with exception: No response received within reply timeout. Timeout was 15000ms (~15s). Used filter: No filter used or filter was ‘null’.”

Hi @hilmyas,

Please share the code snippet that shows the flow as you mentioned above.

I wish to confirm that CometChat.login(their_id, apikey_auth); is being called in onSuccess callback of CometChat.createUser() or equivalent REST API call.

Warm Regards,

Ketan Yekale
CometChat Pro

Also, since you are trying to create a user regardless of already created it returns the error code 400 when the UID already exists in CometChat Pro.

In order to avoid this error, you can add a new column or a mapping table that store the information about users existence in CometChat Pro and creates user only when the mapping is not present or column value is NULL and add the mapping mapping or set the column value on success creation of the user.

Warm Regards,

Ketan Yekale
CometChat Pro

1 Like

OK, I will change my code in my app’s next release. Thank you

Function createCometUser() is called after successfully login to my server

fun createCometUser() {
val apiKey = resources.getString(R.string.apiKey) // Replace with your API Key.
val user = User()
val avatar = Preference.getString(this, USER_PHOTO, “”)
user.uid = Preference.getString(this, USER_ID)
user.name = Preference.getString(this, USER_FULLNAME)
user.avatar = if (!avatar.contains(“http://”) && !avatar.contains(“https://”)) “http://example.jpg” else avatar

    CometChat.createUser(user, apiKey, object : CometChat.CallbackListener<User>() {
        override fun onSuccess(user: User) {
            Timber.e("createUser ${user}")
            loginComet()
        }

        override fun onError(e: CometChatException) {
            Timber.e("createUser ${e.message}")
            loginComet()
        }
    })
}

fun loginComet() {
CometChat.login(Preference.getString(this, USER_ID),
resources.getString(R.string.apiKeyAuth),
object : CometChat.CallbackListener() {
override fun onSuccess(p0: User?) {
Timber.e(“Login Successful : ${p0?.toString()}”)
val topic = resources.getString(R.string.appId) + “user” + Preference.getString(this@PinActivity, USER_ID)

                    FirebaseMessaging.getInstance().subscribeToTopic(topic)
                }

                override fun onError(p0: CometChatException?) {
                    Timber.e("Login failed with exception: ${p0?.message}")
                }
            })
}

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.