Skip to content

Instantly share code, notes, and snippets.

@wajahatkarim3
Created January 31, 2021 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wajahatkarim3/548661d3d71e9a8461666739cf868076 to your computer and use it in GitHub Desktop.
Save wajahatkarim3/548661d3d71e9a8461666739cf868076 to your computer and use it in GitHub Desktop.
Login Firebase and CometChat user
var auth = FirebaseAuth.getInstance()
auth.signInWithEmailAndPassword(bi.txtEmail.text.toString(), bi.txtPassword.text.toString())
.addOnCompleteListener { task ->
if (task.isSuccessful) {
var firebaseUser = auth.currentUser
CometChat.login(firebaseUser!!.uid, getString(R.string.auth_key), object : CometChat.CallbackListener<User>() {
override fun onSuccess(u: User?) {
if (u?.metadata?.has("isDoctor") == true && u.metadata?.getBoolean("isDoctor") == true) {
val i = Intent(applicationContext, DoctorMainActivity::class.java)
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(i)
finish()
}
else {
val i = Intent(applicationContext, MainActivity::class.java)
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(i)
finish()
}
}
override fun onError(ex: CometChatException?) {
Snackbar.make(bi.root, ex?.localizedMessage ?: "Couldn't login CometChat user", Snackbar.LENGTH_SHORT).show()
}
})
} else {
Snackbar.make(bi.root, "Couldn't login Firebase user", Snackbar.LENGTH_SHORT).show()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment