Created
January 31, 2021 18:07
-
-
Save wajahatkarim3/548661d3d71e9a8461666739cf868076 to your computer and use it in GitHub Desktop.
Login Firebase and CometChat user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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