1

I'm using angular v13 and firebaseui and @angular/fire for authentication base on firebase V9 web modular , all sign in methods authentication providers are working except the phone authentication I got error type in console and even RecaptchaVerifier not showed and I got message error "Solve the reCAPTCHA"

ERROR TypeError: app.auth is not a function at new RecaptchaVerifier (index.esm2017.js:931:13) at K.phoneSignInStart (esm.js:339:310)

app.module.ts

 imports: [
    BrowserModule,
    provideFirebaseApp(() => initializeApp(environment.firebase)),
    provideAuth(() => getAuth())
  ]
import * as firebaseui from 'firebaseui'
import {Auth, PhoneAuthProvider
} from '@angular/fire/auth'

constructor(private auth:Auth){
    const ui=new firebaseui.auth.AuthUI(this.auth)
    ui.start('#firebaseui-auth-container', {
      signInOptions: [
        {provider:PhoneAuthProvider.PROVIDER_ID,
          recaptchaParameters: {
            type: 'image',
            size: 'normal',
            badge: 'bottomleft' 
          }
        }              
      ]
     })

I require the official way using official firebaseui

1 Answer 1

3

Using the Firebase Authentication SDK it works

import {Auth,RecaptchaVerifier,signInWithPhoneNumber,PhoneAuthProvider,signInWithCredential} from '@angular/fire/auth'
import {FormGroup,FormControl} from '@angular/forms';
import {Subject, tap} from 'rxjs';

constructor(private auth: Auth) { }
  phoneNumber$=new Subject<string>();
  code$=new Subject<string>();
  phoneNumberForm=new FormGroup({phoneNumberInput:new FormControl('')})
  verifyForm=new FormGroup({codeInput:new FormControl('')})
  displayPhoneDiv=true;
  displayCodeDiv=false;
  
  ngOnInit(): void {
    let appVerifier= new RecaptchaVerifier('recaptcha-container', {
      'size':'invisible', //'normal'
      'callback': (response:any) => {},
      'expired-callback': () => {}
    }, this.auth)

    this.phoneNumber$.pipe(
      tap((phoneNumber:string) =>{
        this.displayPhoneDiv=false;
        signInWithPhoneNumber(this.auth,phoneNumber,appVerifier)
          .then((confirmationResult) => {          
          this.displayCodeDiv=true
          this.code$.pipe(
            tap((code) => {
              console.log(confirmationResult)
              var credential =PhoneAuthProvider.credential(confirmationResult.verificationId,code)
              signInWithCredential(this.auth,credential)
              .then((result) => {
                this.displayCodeDiv=false
                console.log(result)
              })
            })).subscribe()
          })
      })
    ).subscribe()         
  }

  getPhoneNumber(){
    this.phoneNumber$.next(this.phoneNumberForm.controls['phoneNumberInput'].value)
  }
  getCode(){
    this.code$.next(this.verifyForm.controls['codeInput'].value)
  }

<div *ngIf="displayPhoneDiv">
    <h2>Phone Number</h2>
    <form [formGroup]="phoneNumberForm" (ngSubmit)="getPhoneNumber()">
      <input 
      formControlName="phoneNumberInput">
      <button type="submit">Sign in</button>
  </form>  
  </div>
  
  <div *ngIf="displayCodeDiv">
    <h2>Verify code</h2>
      <form [formGroup]="verifyForm" (ngSubmit)="getCode()">
        <input 
        formControlName="codeInput">
        <button type="submit">Verify Code</button>
    </form>  
    </div>
  
  <div id="recaptcha-container"></div>

Sign up to request clarification or add additional context in comments.

1 Comment

Answered using, Firebase Authentication SDK, Any one can help to answer using Firebase UI ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.