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

Fix android phone authentication #308

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

CharlesEtieve
Copy link

Current behavior blocks sms code user input until auto retrieval timeout is reached.

Documentation states it is not recommended to enable user input after sms code retrieval timeout, we should rather enable user input after code sent.
https://firebase.google.com/docs/auth/android/phone-auth#oncodeautoretrievaltimeoutstring-verificationid

So I moved the getVerificationCode() from onCodeAutoRetrievalTimeOut() to onCodeSent() and it works well on my project.

Copy link
Member

@nbransby nbransby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! And sorry for the delay in reviewing.

What about JS and iOS, do they suffer the same issue?

@@ -104,6 +101,9 @@ actual class PhoneAuthProvider(val android: com.google.firebase.auth.PhoneAuthPr
}
}

override fun onCodeAutoRetrievalTimeOut(verificationId: String) {
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll need to fail the CompletableDeferred here too otherwise it will hang?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we should make a response.complete() in onCodeAutoRetrievalTimeOut(), because the response can be completed only once and we would not be able to make response.complete() after user input when onCodeAutoRetrievalTimeOut() is called before.
Maybe we could add a function inside PhoneVerificationProvider: onCodeAutoRetrievalTimeOut()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't want to complete, you fail it with the appropriate exception

@@ -104,6 +101,9 @@ actual class PhoneAuthProvider(val android: com.google.firebase.auth.PhoneAuthPr
}
}

override fun onCodeAutoRetrievalTimeOut(verificationId: String) {
}

override fun onVerificationCompleted(credential: com.google.firebase.auth.PhoneAuthCredential) {
response.complete(Result.success(AuthCredential(credential)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know this isnt your code but we shoudlnt be wrapping the result in a Result - can just fail the CompletableDeferred with completeExceptionally

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So instead of response.complete(Result.failure(exception)) we should do response.completeExceptionally(exception)?

@CharlesEtieve
Copy link
Author

CharlesEtieve commented Aug 7, 2022

Thanks for the PR! And sorry for the delay in reviewing.

What about JS and iOS, do they suffer the same issue?

Hello, sorry for the late reply!
I cannot tell you about the other platforms but I guess not.
My iOS coworker did not implement authentication with this SDK.
It was a little bit too complex with the suspend function inside PhoneVerificationProvider.
I will tell you later about that.
We do not have a JS app.

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

Successfully merging this pull request may close these issues.

None yet

3 participants