# Firebase auth in SDK 9 does not work on ios sim or devices

**URL:** <https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362>\
**Category:** Ionic Framework\
**Created:** [September 23, 2021, 8:50pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362 "2021-09-23T20:50:37Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![DonTheDude](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/donthedude/32/147544_2.png) [@DonTheDude](https://forum.ionicframework.com/u/DonTheDude)\
**Post date:** [September 23, 2021, 8:50pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/1 "2021-09-23T20:50:37Z")

</div>

I recently moved to the firebase v9 sdk for a brand new ionic/angular project. I was able to get the signInWithEmailAndPassword call to work in a web browser but it hangs in iphone simulators and devices. Strangely, it works in the ipad simulator. If I take the same app and switch it to the v8 firebase sdk, the login process works on all sims and devices.  
I contacted Firebase tech support. I got the “It’s not us it’s ionic” response. Was not the kind of response I expected.  
Any who, be aware that the firebase v9 sdk has problems when used with ionic.

---

<div class="post-metadata">

**Author:** ![archiru](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@archiru](https://forum.ionicframework.com/u/archiru)\
**Post date:** [September 28, 2021, 10:37pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/2 "2021-09-28T22:37:05Z")

</div>

I am getting precisely the same error, (with signInWithEmailAndPassword, on an Ionic Angular project, on the IOS simulator). I will try and move back to Firebase v8.

---

<div class="post-metadata">

**Author:** ![DonTheDude](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/donthedude/32/147544_2.png) [@DonTheDude](https://forum.ionicframework.com/u/DonTheDude)\
**Post date:** [September 28, 2021, 11:04pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/3 "2021-09-28T23:04:43Z")

</div>

There is an update on this. You can use the new v9 sdk if you want. You just need to initialize auth like so:

```auto
init() {
    const app = initializeApp(environment.firebase);
    if (Capacitor.isNativePlatform) {
      initializeAuth(app, {
        persistence: indexedDBLocalPersistence
      });
    }
    this.firestore = getFirestore(app);
  }

```

See this for more details: [Auth does not work in ionic apps on iphone devices or sims · Issue #5552 · firebase/firebase-js-sdk · GitHub](https://github.com/firebase/firebase-js-sdk/issues/5552)

If you want to use FB or Google auth, you need to look at this: [Authenticate Using OAuth Providers with Cordova &nbsp;|&nbsp; Firebase](https://firebase.google.com/docs/auth/web/cordova?authuser=0)

---

<div class="post-metadata">

**Author:** ![archiru](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@archiru](https://forum.ionicframework.com/u/archiru)\
**Post date:** [September 29, 2021, 12:45am UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/4 "2021-09-29T00:45:24Z")

</div>

Thanks a lot for your answer. Do you know what that would look like in the app.module.ts file when using AngularFire? I can’t get it to work.

---

<div class="post-metadata">

**Author:** ![DonTheDude](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/donthedude/32/147544_2.png) [@DonTheDude](https://forum.ionicframework.com/u/DonTheDude)\
**Post date:** [September 29, 2021, 3:36pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/5 "2021-09-29T15:36:13Z")

</div>

I don’t know. I would have to research it. If I get some time, I might get into it.

Regards,  
Don Morris

---

<div class="post-metadata">

**Author:** ![uncoded](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@uncoded](https://forum.ionicframework.com/u/uncoded)\
**Post date:** [September 30, 2021, 4:41pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/6 "2021-09-30T16:41:09Z")

</div>

Don you’re a legend - I’ve been struggling with this for 2 days. Thanks!

---

<div class="post-metadata">

**Author:** ![DonTheDude](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/donthedude/32/147544_2.png) [@DonTheDude](https://forum.ionicframework.com/u/DonTheDude)\
**Post date:** [September 30, 2021, 6:14pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/7 "2021-09-30T18:14:25Z")

</div>

I didn’t solve it. This guy did [jayordway (Jay Ordway) · GitHub](https://github.com/jayordway)

---

<div class="post-metadata">

**Author:** ![uncoded](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@uncoded](https://forum.ionicframework.com/u/uncoded)\
**Post date:** [October 1, 2021, 8:42am UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/8 "2021-10-01T08:42:46Z")

</div>

I saw that. But I wouldn’t have if you hadn’t posted here, so thanks anyway.

---

<div class="post-metadata">

**Author:** ![inorganik](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/inorganik/32/139605_2.png) [@inorganik](https://forum.ionicframework.com/u/inorganik)\
**Post date:** [November 11, 2021, 8:04pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/9 "2021-11-11T20:04:46Z")

</div>

If anyone is wondering where to put that code, I put it in app.component and it is working in the iOS simulator. Here is the full file with imports:

```auto
import { Component } from '@angular/core';
import { Capacitor } from '@capacitor/core';
import { initializeApp } from 'firebase/app';
import { indexedDBLocalPersistence, initializeAuth } from 'firebase/auth';
import { environment } from 'src/environments/environment';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss'],
})
export class AppComponent {
  constructor() {
    const app = initializeApp(environment.firebase);
    if (Capacitor.isNativePlatform) {
      initializeAuth(app, {
        persistence: indexedDBLocalPersistence
      });
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![merv63](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@merv63](https://forum.ionicframework.com/u/merv63)\
**Post date:** [January 1, 2022, 3:58am UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/10 "2022-01-01T03:58:53Z")

</div>

Hi,

What have you got in app.module?

I am getting already initialised errors.

Thanks in advance,

EDIT

I worked it out.

I rewrote the app with only angular/fire and not firebase

---

<div class="post-metadata">

**Author:** ![whit3](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/whit3/32/140469_2.png) [@whit3](https://forum.ionicframework.com/u/whit3)\
**Post date:** [January 10, 2022, 1:55pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/11 "2022-01-10T13:55:16Z")

</div>

Thanks it really helped me solve my issue @

> [@Can't login to my firebase backend base app on iOS but works on android](https://forum.ionicframework.com/t/cant-login-to-my-firebase-backend-base-app-on-ios-but-works-on-android/219216):
>
> I need help with my app on iOS. I’ve completed building the app using firebase for the backend, while building I was testing it using only android device and emulator since I didn’t had a MacBook everything was good and working well, because of the fact that I need it on iOS too I bought MacBook pro 2012 recently and have installed all that is need to run the app and it’s runs on the emulator without errors but can’t l login on the emulator, if I try with a wrong password it returns an error me…

---

<div class="post-metadata">

**Author:** ![ryanstables](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ryanstables/32/140845_2.png) [@ryanstables](https://forum.ionicframework.com/u/ryanstables)\
**Post date:** [February 17, 2022, 3:01pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/12 "2022-02-17T15:01:47Z")

</div>

**Edit** : I was also struggling with already initialized’ errors, but as a workaround, I managed to add the initializeAuth calls into app.module, which now looks something like this:

```auto
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { enableIndexedDbPersistence, getFirestore, provideFirestore } from '@angular/fire/firestore';
import {provideAuth, getAuth, initializeAuth, indexedDBLocalPersistence} from '@angular/fire/auth';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { environment } from 'src/environments/environment';
import { Capacitor } from '@capacitor/core';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
      BrowserModule,
      IonicModule.forRoot(),
      AppRoutingModule,
      provideFirebaseApp(() => {
        const app = initializeApp(environment.firebase);
          if (Capacitor.isNativePlatform) {
            initializeAuth(app, {
                persistence: indexedDBLocalPersistence
            });
        }
          return app;
        }),
      provideAuth(() => getAuth()),
      provideFirestore(() => {
        const firestore = getFirestore();
        enableIndexedDbPersistence(firestore);
        return firestore;
      }),
    ],
  providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
  bootstrap: [AppComponent],
})
export class AppModule {}

```

---

<div class="post-metadata">

**Author:** ![Razzvy](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/razzvy/32/141093_2.png) [@Razzvy](https://forum.ionicframework.com/u/Razzvy)\
**Post date:** [March 20, 2022, 5:59pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/13 "2022-03-20T17:59:36Z")

</div>

This was the only thing that worked for me, thanks !!

---

<div class="post-metadata">

**Author:** ![codemickey78](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@codemickey78](https://forum.ionicframework.com/u/codemickey78)\
**Post date:** [March 21, 2022, 3:43am UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/14 "2022-03-21T03:43:34Z")

</div>

Can please share your app.module and how you made it work. I have been trying to resolve the issue buh no success

---

<div class="post-metadata">

**Author:** ![Razzvy](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/razzvy/32/141093_2.png) [@Razzvy](https://forum.ionicframework.com/u/Razzvy)\
**Post date:** [March 21, 2022, 12:14pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/15 "2022-03-21T12:14:18Z")

</div>

I thing you are interested in this part:

```auto
    provideFirebaseApp(() => {
      const app = initializeApp(firebaseConfig);
      if (Capacitor.isNativePlatform) {
        initializeAuth(app, {
          persistence: indexedDBLocalPersistence
        });
      }
      return app;
    }),
    provideFirestore(() => {
      const firestore = getFirestore();
      enableIndexedDbPersistence(firestore);
      return firestore;
    }),
    provideAuth(() => getAuth()),

```

this is inside the imports array.

---

<div class="post-metadata">

**Author:** ![codemickey78](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@codemickey78](https://forum.ionicframework.com/u/codemickey78)\
**Post date:** [March 21, 2022, 12:44pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/16 "2022-03-21T12:44:51Z")

</div>

I copied that but still same issue. Can please share your app.module? Did you do any changes in your app.component.ts?

---

<div class="post-metadata">

**Author:** ![Razzvy](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/razzvy/32/141093_2.png) [@Razzvy](https://forum.ionicframework.com/u/Razzvy)\
**Post date:** [March 21, 2022, 1:43pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/17 "2022-03-21T13:43:56Z")

</div>

My app module is not relevant, but I will post it:

```auto
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {RouteReuseStrategy} from '@angular/router';

import {IonicModule, IonicRouteStrategy} from '@ionic/angular';

import {AppComponent} from './app.component';
import {AppRoutingModule} from './app-routing.module';

import {HttpClient, HttpClientModule} from '@angular/common/http';
import {TranslateLoader, TranslateModule} from '@ngx-translate/core';
import {TranslateHttpLoader} from '@ngx-translate/http-loader';

import {firebaseConfig} from './***';
import {provideFirebaseApp, initializeApp} from '@angular/fire/app';
import {enableIndexedDbPersistence, getFirestore, provideFirestore} from '@angular/fire/firestore';
import {getAuth, initializeAuth, provideAuth, indexedDBLocalPersistence} from '@angular/fire/auth';
import {AuthenticationGuardService} from './authentication-guard.service';
import {AuthenticationService} from './authentication.service';
import {Capacitor} from '@capacitor/core';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    BrowserModule,
    IonicModule.forRoot(),
    AppRoutingModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: httpLoaderFactory,
        deps: [HttpClient]
      }
    }),
    HttpClientModule,
    provideFirebaseApp(() => {
      const app = initializeApp(firebaseConfig);
      if (Capacitor.isNativePlatform) {
        initializeAuth(app, {
          persistence: indexedDBLocalPersistence
        });
      }
      return app;
    }),
    provideFirestore(() => {
      const firestore = getFirestore();
      enableIndexedDbPersistence(firestore);
      return firestore;
    }),
    provideAuth(() => getAuth()),
  ],
  providers: [AuthenticationGuardService,AuthenticationService, {provide: RouteReuseStrategy, useClass: IonicRouteStrategy}],
  bootstrap: [AppComponent],
})
export class AppModule {
}

// required for AOT compilation
export function httpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http);
}

```

in the app.component.ts I don’t have anything related to the initialisation.

---

<div class="post-metadata">

**Author:** ![ftftft](https://avatars.discourse-cdn.com/v4/letter/f/ee7513/32.png) [@ftftft](https://forum.ionicframework.com/u/ftftft)\
**Post date:** [December 26, 2023, 12:25pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/18 "2023-12-26T12:25:15Z")

</div>

Thank you so much to you and Jay Ordway! I also spent a frustrating amount of time trying to solve this.

---

<div class="post-metadata">

**Author:** ![marcelob12](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@marcelob12](https://forum.ionicframework.com/u/marcelob12)\
**Post date:** [January 19, 2024, 2:27pm UTC](https://forum.ionicframework.com/t/firebase-auth-in-sdk-9-does-not-work-on-ios-sim-or-devices/215362/19 "2024-01-19T14:27:13Z")

</div>

Realmente me funciono, estoy muy agradecido contigo, gracias gracias gracias!!!
