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

signInWithPhoneNumber throws error on iOS with cordova and Ionic #8768

Open
willemjanvankranenburg opened this issue Feb 6, 2025 · 1 comment

Comments

@willemjanvankranenburg
Copy link

Operating System

iOS 17.5.1

Environment (if applicable)

Ionic 8, Cordova CLI 12, Cordova iOS 7.1.1, @ionic/angular 8.4.2

Firebase SDK Version

11.2.0

Firebase SDK Product(s)

Auth

Project Tooling

Ionic Cordova Angular App, build for iOS

Detailed Problem Description

When calling the signInWithPhoneNumber method from 'firebase/auth' everything works fine for web and andriod. But using the same build for iOS I get the following Error:

Image

I followed the steps from https://firebase.google.com/docs/auth/ios/phone-auth#set-up-recaptcha-verification, but this had no other result.

Steps and code to reproduce issue

Create a clean Ionic Cordova app using Angular withionic start phoneLogin blank --cordova --type=angular
Add firebase package with npm i firebase
make sure the initializeAp from firebase/app is called in app.module.ts with your firebase project config

In home.page.ts add the following:

import {
  Auth,
  getAuth,
  RecaptchaVerifier,
  signInWithPhoneNumber,
} from 'firebase/auth';


let window: any;

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
  standalone: false,
})
export class HomePage implements ViewDidEnter {
  private auth: Auth;
  constructor(private formBuilder: FormBuilder) {
    this.auth = getAuth(getApp());      
  }
  public ionViewDidEnter(): void {
    window = new RecaptchaVerifier(this.auth, 're-captcha-container', {
      size: 'invisible',
    });
  }

  public async sendVerificationSMS(): Promise<void> {
    const phoneNumber: string = '<PHONENUMBER>';
    try {
      const confirmationResult = await signInWithPhoneNumber(this.auth, phoneNumber, window);
      console.log(confirmationResult)
    } catch (error) {
      console.log(error);
    }
  }
}

The HTML for home.page should have the following;

<ion-header [translucent]="true">
  <ion-toolbar>
    <ion-title> Blank </ion-title>
  </ion-toolbar>
</ion-header>

<ion-content [fullscreen]="true">
  <ion-header collapse="condense">
    <ion-toolbar>
      <ion-title size="large">Blank</ion-title>
    </ion-toolbar>
  </ion-header>
    <ion-button color="primary" (click)="sendVerificationSMS()">
      SEND
    </ion-button>
  <div class="reCaptchaContainer" id="re-captcha-container"></div>
</ion-content>

In config.xml add

    <preference name="Hostname" value="url.for.you" />
    <preference name="Scheme" value="https" />

make sure the url.for.you in Hostname is an authorised domain in your firebase project > Authentication > Settings > Authorised domains


  • in your ionic project; run ionic cordova platform add android and ionic cordova build android, install the build APK on an Android device and everything works
@willemjanvankranenburg willemjanvankranenburg added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Feb 6, 2025
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@jbalidiong jbalidiong added api: auth needs-attention and removed needs-triage new A new issue that hasn't be categoirzed as question, bug or feature request labels Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants