Home > Mobile >  Firebase emulator, set test phone sms code
Firebase emulator, set test phone sms code

Time:03-05

When trying to authenticate with a phone against firebase auth emulator, the emulator output those kinds of messages:

To verify the phone number  16505551234, use the code 376579.

I would like to know if there is a way to set that code to be something static so I can run some integrations tests.

Just to be clear I already added a test phone to firebase (not the emulator) with it's code, but the emulator does not pick it up. The emulator ui interface does not seem to have the option to add one either.

It just generates a new code for every authentication and I want to put a static one for example "123456"

CodePudding user response:

The documentation covers adding phone numbers for testing.

Create fictional phone numbers and verification codes

  1. In the Firebase console, open the Authentication section.
  2. In the Sign in method tab, enable the Phone provider if you haven't already.
  3. Open the Phone numbers for testing accordion menu.
  4. Provide the phone number you want to test, for example: 1 650-555-3434.
  5. Provide the 6-digit verification code for that specific number, for example: 654321.
  6. Add the number. If there's a need, you can delete the phone number and its code by hovering over the corresponding row and clicking the trash icon.

Importantly, the test numbers you use should not exist! Especially, don't use your own phone number for these tests!

Further down in the documentation, you will find more details regarding integration testing.

CodePudding user response:

There is currently no way to set a static verification code as per the source here :

https://github.com/firebase/firebase-tools/blob/7271c958eea82b8d223c0e581a94e3b5b7e57619/src/emulator/auth/state.ts

I'll submit a PR though, which might not be accepted.

https://github.com/firebase/firebase-tools/pull/4255

  • Related