question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auth does not work in ionic apps on iphone devices or sims

See original GitHub issue

Version info

Angular 12.1.1

Firebase 9

@angular/fire 7.0.4

ionic 5.5.2

How to reproduce these conditions

Create a sign in with email and password login. Will work in browser; will not work in iphone simulator or iphone device. It will just hang, waiting for a login result.

Steps to set up and reproduce

  1. clone git clone https://donhmorris@bitbucket.org/donhmorris/testlogin.git
  2. run npm i
  3. run ionic lab
  4. login in browser with credentials: email = ‘don@test.com’. pwd = ‘password’
  5. Message will be displayed in app that says “Signed in as don@test.com” and Logout button is displayed on success. A toast will appear in red if an error occurs.
  6. stop ionic lab; run ionic cap run ios
  7. select an iphone simulator model. Any version will do. Recommend iphone 13.
  8. attempt to login using the previous credentials
  9. nothing will happen. no errors, exceptions or anything. app just hangs

Notes A firebase project is setup to specifically test the supplied demo app.

Debug output

** Errors in the JavaScript console ** None ** Output from firebase.database().enableLogging(true); **

** Screenshots **

Expected behavior

Login is successful and a message is displayed showing the email used to sign in.

Actual behavior

App hangs with no error messages

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:26 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
NLuegcommented, Oct 13, 2021

If anyone also has this issue, I solved it as suggested in the issue https://github.com/firebase/firebase-js-sdk/issues/5019 with this code:

import {
  getAuth,
  indexedDBLocalPersistence,
  initializeAuth,
  provideAuth,
} from '@angular/fire/auth';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    ...
    provideAuth(() => {
      if (Capacitor.isNativePlatform()) {
        return initializeAuth(getApp(), {
          persistence: indexedDBLocalPersistence,
        });
      } else {
        return getAuth();
      }
    }),
  ]
})
6reactions
rodrigorealcommented, Nov 13, 2021

If anyone also has this issue, I solved it as suggested in the issue firebase/firebase-js-sdk#5019 with this code:

import {
  getAuth,
  indexedDBLocalPersistence,
  initializeAuth,
  provideAuth,
} from '@angular/fire/auth';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    ...
    provideAuth(() => {
      if (Capacitor.isNativePlatform()) {
        return initializeAuth(getApp(), {
          persistence: indexedDBLocalPersistence,
        });
      } else {
        return getAuth();
      }
    }),
  ]
})

@NLueg thank you man, saved my day, was struggling here for hours.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auth does not work in ionic apps on iphone devices or sims
Reverting back to v8 works fine. Something was broken in v9 for use with ionic framework.
Read more >
Firebase auth in SDK 9 does not work on ios sim or devices
I recently moved to the firebase v9 sdk for a brand new ionic/angular project. I was able to get the signInWithEmailAndPassword call to...
Read more >
Firebase auth web SDK not working on Ionic iOS?
My issue is the login with the email and password function works fine on android but on iOS, the promise is never returned...
Read more >
Build an Ionic App with User Authentication
OIDC allows you to authenticate directly against the Okta API, and this article shows you how to do just that in an Ionic...
Read more >
PushKit | Apple Developer Forums
I'm trying to do push notification for apple wallet pass via PHP. ... iOS VoIP App running on M1 Mac Callkit and Pushkit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found