angularfire: Auth does not work in ionic apps on iphone devices or sims
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
- clone git clone https://donhmorris@bitbucket.org/donhmorris/testlogin.git
- run npm i
- run ionic lab
- login in browser with credentials: email = ‘don@test.com’. pwd = ‘password’
- 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.
- stop ionic lab; run ionic cap run ios
- select an iphone simulator model. Any version will do. Recommend iphone 13.
- attempt to login using the previous credentials
- 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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 28 (1 by maintainers)
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:
@NLueg thank you man, saved my day, was struggling here for hours.
The real problem: firebase-js-sdk on mobile iOS assumes google API (gapi) exists on the window, even when it isn’t used.
I found a work around: Mock window.gapi before using firebase auth login:
@bocodigital
app.module.ts
And for exemple in my auth service you need to do something like that:
This also resolved my issue, still can’t found an official bug on this. The mix between web and native is still blurry on a so popular tool.
You can do the same thing with angular fire. Playing bf 2042 right now. I’ll see if I can grab my code for angular fire in a few b