angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Firebase Auth responds with _getRecaptchaConfig is not a function during signIn with Email and password

Open coastriders opened this issue 2 years ago • 17 comments

Capture d’écran 2023-09-29 à 10 04 31 Capture d’écran 2023-09-29 à 10 04 01 Capture d’écran 2023-09-29 à 10 03 51 Capture d’écran 2023-09-29 à 10 06 42

I have been trying to understand why something always does not work when we follow your docs and examples.

I expected your 6-month-updated-doc to be of use.

I have obviously tried so many things before yielding to the temptation of this issue

coastriders avatar Sep 29 '23 08:09 coastriders

This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Sep 29 '23 08:09 google-oss-bot

Post code, not pictures.

The error is on line 54 of your login.component.ts, which you have not shown.

rgant avatar Oct 07 '23 11:10 rgant


// that's my whole  log.component.ts // line 54 that's the catch (e)

import { Component, HostListener, Inject, OnDestroy, OnInit } from '@angular/core';
import { Observable, of, tap } from 'rxjs';
import { InputModel } from 'src/interfaces/Input';
import { Auth, signInWithEmailAndPassword } from '@angular/fire/auth';


@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit, OnDestroy {

  private auth: Auth = Inject(Auth)

  items:InputModel[] = [
    {
      name: 'email',
      placeholder: 'Email',
      type: 'email',

    },
    {
      name: 'password',
      placeholder: 'Mot de passe',
      type: 'password',
      
    }
  ]

  model = {
    email: "",
    password: "",
  }


  ngOnInit() {
    console.log('✅ - login page has mounted')
    console.log(' auth ---', this.auth)
  }

  ngOnDestroy() {
    console.log('login page has unmounted')
  }


  @HostListener('submit', ['$event'])
  onSubmitForm(event:Event){
    event.preventDefault();
    console.log('submitForm', this.model)
   signInWithEmailAndPassword(this.auth, this.model.email, this.model.password)
      .then((user) => {
        console.log('🥎 user', user);
      })
      .catch((e) => {
        console.log('error', e)
      })
  }

  @HostListener('input', ['$event'])
  onInputChange(event:Event, name:string):void{
 
     const target:any = event.target

     if(name === 'email'){
      this.model.email = target.value
      console.log('this.model', this.model)
     }

     if(name === 'password'){
      this.model.password = target.value
      console.log('this.model', this.model)
     }
 
  }
}

coastriders avatar Oct 07 '23 12:10 coastriders

Please re-read the code block documentation I linked to above and format your post appropriately.

For example: ```ts // All on a line by itself ☝️ Your Code Here // All on a line by itself 👇 ```

Don't mix async await and .then() and .catch().

rgant avatar Oct 07 '23 12:10 rgant

The mixing does not change a thing, thanks for trying @rgant

coastriders avatar Oct 07 '23 14:10 coastriders

The mixing does not change a thing, thanks for trying @rgant

Not mixing async and then makes for better code quality. Better code quality makes it easy for follow code and improve it. And yes, that has (probably) nothing to do with your issue.

It is difficult to read your code when not properly formatted. So I haven't yet because I am waiting for you to resolve that.

rgant avatar Oct 07 '23 14:10 rgant

@rgant I wonder if the problem is not related to the versions of the dependencies I use. Capture d’écran 2023-10-07 à 16 46 00

borisrose avatar Oct 07 '23 14:10 borisrose

That doesn't tell you what is installed. You need to run ng version to get an overview of the installed versions that Angular things are interesting.

You need to run npm list @angular/fire firebase rxfire and similar commands to get the installed version of packages in your repo. The versions in your package.json appear appropriate.

rgant avatar Oct 07 '23 16:10 rgant

Where is your initializeApp or otherwise setup of Angular Firebase? Show that code?

https://stackoverflow.com/a/76592882

rgant avatar Oct 08 '23 04:10 rgant


import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { getApp, initializeApp,provideFirebaseApp } from '@angular/fire/app';
import { environment } from '../environments/environment';
import { provideAuth,getAuth } from '@angular/fire/auth';
import { ReCaptchaV3Provider, initializeAppCheck, provideAppCheck } from '@angular/fire/app-check';
import { provideFirestore,getFirestore } from '@angular/fire/firestore';
import { provideFunctions,getFunctions } from '@angular/fire/functions';
import { provideMessaging,getMessaging } from '@angular/fire/messaging';
import { provideStorage,getStorage } from '@angular/fire/storage';
import { DashboardComponent } from './dashboard/dashboard.component';
import { LoginComponent } from './login/login.component';
import { InputComponent } from './input/input.component';

@NgModule({
  declarations: [
    AppComponent,
    DashboardComponent,
    LoginComponent,
    InputComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    provideFirebaseApp(() => initializeApp(environment.firebase)),
    provideAppCheck(() => initializeAppCheck(getApp(), {
      provider: new ReCaptchaV3Provider("...."),
      
    })),
    provideAuth(() => getAuth()),
    provideFirestore(() => getFirestore()),
    provideFunctions(() => getFunctions()),
    provideMessaging(() => getMessaging()),
    provideStorage(() => getStorage())
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }



coastriders avatar Oct 08 '23 20:10 coastriders

Capture d’écran 2023-10-08 à 22 58 56

coastriders avatar Oct 08 '23 20:10 coastriders

Capture d’écran 2023-10-08 à 23 00 39

coastriders avatar Oct 08 '23 21:10 coastriders

I have managed to find a solution here it is


import { Component, Inject, OnInit } from '@angular/core';
import { FirebaseApp } from '@angular/fire/app';
import { Auth, signInWithEmailAndPassword } from '@angular/fire/auth';
import { getAuth } from 'firebase/auth';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
  title = 'th-app';

  constructor(private app: FirebaseApp) {}

  ngOnInit() {
    const auth = getAuth(this.app);
    console.log('auth', auth);
    signInWithEmailAndPassword(auth, "[email protected]", "password")
      .then((res) => {
          console.log('res', res)
      })
      .catch((err) => {
        console.log('err', err)
      })
  }


}


coastriders avatar Oct 08 '23 22:10 coastriders

// another way of writing it 

import { Component, Inject, OnInit } from '@angular/core';
import { FirebaseApp } from '@angular/fire/app';
import { Auth, signInWithEmailAndPassword, getAuth } from '@angular/fire/auth';


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
  title = 'th-app';
  auth: Auth;

  constructor(private app: FirebaseApp) {
    this.auth = getAuth(this.app);
  }

  ngOnInit() {
   
    console.log('auth', this.auth);
    signInWithEmailAndPassword(this.auth, "[email protected]", "password")
      .then((res) => {
          console.log('res', res)
      })
      .catch((err) => {
        console.log('err', err)
      })
  }


}

coastriders avatar Oct 08 '23 22:10 coastriders

image I also got the same error. what to do?

Nazmul-Hassan10 avatar Oct 09 '23 04:10 Nazmul-Hassan10

Look UP ! 😅✌️

borisrose avatar Oct 09 '23 07:10 borisrose

Look UP ! 😅✌️

I found the solution. I had to push my project to GitHub, clone it, and then run the 'npm i' command. 🙂

Nazmul-Hassan10 avatar Oct 10 '23 04:10 Nazmul-Hassan10