I'm just trying to get a Flutter app released on the app store and am using the Firebase Auth plugin.
One of the issues that came back from the review was, that the app seems to be hanging during sign-in or registering a new user.
After my investigation, I stumbled over the case when the network connection is not stable and or not available. The timeout for signInWithEmailAndPassword seems to be around 3 minutes before I get the exception ERROR_NETWORK_REQUEST_FAILED. That is way too long. No end-user will wait 3 minutes.
Since I didn't find the option in the API to cancel a network request or set a custom timeout, I tried an easy fix and use the timeout method on the future:
FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password).timeout(Duration(seconds: 30))
This seems to work at first and deliver the result, that my loading dialog for the login can be closed after 30 seconds with an error message about the network connection. But if I then activate the network connection before 3 minutes are over, I find myself logged into the app all of a sudden, because FirebaseAuth comes back with an authenticated user. So you could trick some person in signing in with his user/password and make him think it didn't work, then activating the network again and finding yourself logged in with the other person's user.
So this naive solution doesn't work obviously. Now I'm thinking about how I could prevent this case and implement some logic in the onAuthStateChanged event, so that I maybe trigger an immediate signOut again in case the user received the timeout after the 30 seconds before. But that then opens up Pandora's box to a host of other issues and will result in quite some complex logic, because all kinds of other sign-in/sign-out events with the same or other users can have happened in the meantime.
So, how do I go from here? Is there any other simple and reliable solution to set a custom timeout?