'Need my app to login with Google as well as with manual login with email and password
I did the google sign in within the app so when the user first time wants to create an account he can do it with just one click, after that I redirect the user to also create a password and I want to have the functionality that the user can also do manual login as well as log in with google.
in the above case when the user taps on google sign-in on the same time when that done before updating the UI I redirect the user to a new password screen and I take the email from firebase google sign in as we already did and just adding the password from screen to the function like this:
registerUserWithEmailAndPassword(email, password, callback(Boolean)
But the problem is it's not working and I can't figure out how to achieve it.
I will really appreciate your help in this regard.
some relevant code on Google Sign in:
private fun firebaseAuthWithGoogle(idToken: String) {
val credential = GoogleAuthProvider.getCredential(idToken, null)
auth.signInWithCredential(credential)
.addOnCompleteListener(requireActivity()) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success")
FirestoreAuth().getUserDetails { user ->
FirestoreAuth().registerUserWithEmailAndPassword(user.email, "1223abc") {
if (it){
updateUi(FirestoreAuth().auth.currentUser)
}
}
}
hideProgress()
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.exception)
updateUI(null)
hideProgress()
}
}
}
some relevant code on register with email and password function :
fun registerUserWithEmailAndPassword(
email: String,
password: String,
callback: (Boolean) -> Unit
) {
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener() { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "createUserWithEmail:success")
val user = auth.currentUser
callback(true)
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "createUserWithEmail:failure", task.exception)
callback(false)
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
