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

🐛 [FIREBASE_AUTH] Cannot sign in twice with phone number with the emulator #8351

Closed
cedvdb opened this issue Mar 28, 2022 · 7 comments
Closed
Labels
platform: android Issues / PRs which are specifically for Android. plugin: auth resolution: invalid This doesn't seem right and might not belong here. type: bug Something isn't working

Comments

@cedvdb
Copy link

cedvdb commented Mar 28, 2022

When using phone authentication with the firebase emulator and android emulator the authentication works the first time, the firebase emulator generates an sms code. The second time, if the login is fast enough, no such code is generated and the first code is invalidated.


When recording the below gif I noticed the code was actually generated the second time, it is because I did it slowly, keep watching as I tries to do it fast it will fail. Sorry if the gif is a bit slow, I was surprised to see it working at first.

Recording 2022-03-28 at 16 50 23


I made a repro:

https://github.com/cedvdb/flutter_repros/tree/failing_auth

However it might require some setup:

  • it will require that you remove the firebase configs and initialize with your own project so you can run the emulator . So firebase init
  • You'll have to change the values in firebase_options.dart android with the values for firebase config android.
  • Have phone authentication enabled in your fierbase project
  • run emulator with firebase emulators:start

This is blocking for integration testing

@cedvdb cedvdb added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Mar 28, 2022
@yuchenshi
Copy link
Member

Let's merge the discussion into firebase/firebase-tools#4290

@cedvdb
Copy link
Author

cedvdb commented Mar 29, 2022

I'm not sure if the issue comes from here or the emulator. The issue that I opened in the firebase-tools was originally about something else, ence why I'm issuing one here too as it seemed to fit better this repository. I don't usually ask the same issue in multiple repo.

@darshankawar darshankawar added the triage Issue is currently being triaged. label Mar 29, 2022
@darshankawar
Copy link

@cedvdb
Thanks for the report and code sample. Can you provide the entire error log ? Its not clear from the gif as exactly the error is. That would help to debug further.

@darshankawar darshankawar added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Mar 29, 2022
@cedvdb
Copy link
Author

cedvdb commented Mar 29, 2022

I will not furnish a stack trace because that would be misleading. the error is not what should be debugged, this error is essentially generated by me. There is no error happening on the flutterfire front.

The error is essentially saying "hey there is no element in this array" because my repro tries to get the sms code from the emulator, but since the emulator did not generate a code, the array of code is empty. So an error happens because I try to access an element of an empty array. But the stack trace of this error is irrelevant, this is from my code:

  Future<String> retrieveSmsCode() async {
    final Uri endpoint = Uri(
      scheme: 'http',
      host: '10.0.2.2', // android or localhost for other platforms
      port: 9099,
      path:
          'emulator/v1/projects/${DefaultFirebaseOptions.android.projectId}/verificationCodes',
    );
    final response = await http.get(endpoint);
    if (response.statusCode != 200) {
      throw response.body;
    }
    Map body = jsonDecode(response.body);
    final code = body['verificationCodes'].last['code'];   //// here the error is thrown because the emulator did not generate an sms code
    return code;
  }

Just to be clear,

The bug is that no sms code is generated by the emulator. That could be because:

  • flutterfire fails to send a authentication event to the emulator
  • the emulator fails to answer to an authentication event.

Is this more clear ?

@cedvdb
Copy link
Author

cedvdb commented Mar 30, 2022

@darshankawar Do you need more information from me ? This is still in triage, that's why I'm asking.

@darshankawar
Copy link

Thanks for the update. Keeping it open and labeling it for further insights from the team.

/cc @russellwheatley

@darshankawar darshankawar added plugin: auth platform: android Issues / PRs which are specifically for Android. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. triage Issue is currently being triaged. labels Mar 30, 2022
@russellwheatley
Copy link
Member

Hey @cedvdb, as noted by @yuchenshi, this is a firebase-tools bug to be resolved. FlutterFire has no control over the issuing of verification codes by the emulator. I'd advise tracking here: firebase/firebase-tools#4290. Thanks.

@darshankawar darshankawar added the resolution: invalid This doesn't seem right and might not belong here. label Mar 30, 2022
@firebase firebase locked and limited conversation to collaborators Apr 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: android Issues / PRs which are specifically for Android. plugin: auth resolution: invalid This doesn't seem right and might not belong here. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants