-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auth does not work in ionic apps on iphone devices or sims #2979
Comments
I found that the login function is working, the problem is on change detection of |
Also experiencing this. Downgrading to |
I also found downgrading @angular/fire works as well as using Firebase sdk v8. Looks like this was broken in Firebase sdk 9. |
Going to close as this isn't an issue with AngularFire, please open over on the JS SDK repo. |
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();
}
}),
]
}) |
Fixed here: https://stackoverflow.com/a/69793220/12624390 |
I've the same problem but solution provided by @ejirocodes doesn't work for me. I'm using AngularFireAuth and AngularFireStorage. I can confirm downgrading to @angular/fire": "^6.1.5" and "firebase": "^8.10.0" works. |
@NLueg thank you man, saved my day, was struggling here for hours. |
Can you share how you handled it in your component? |
In your main app component import { Component } from '@angular/core'; @component({ |
Im looking at what @rodrigoreal did. Looks like what @donhmorris is saying is to ditch angularfire all together for native. But it looks like @rodrigoreal added that to his appModule but I don't get how that works. |
@donhmorris are you removing all the angularfire imports from the appModule? |
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 |
@donhmorris thanks!! |
app.module.ts import { provideFirebaseApp, getApp, initializeApp } from '@angular/fire/app';
import { provideAuth, getAuth, indexedDBLocalPersistence, initializeAuth } from '@angular/fire/auth';
import { provideStorage, getStorage } from '@angular/fire/storage';
import { provideMessaging, getMessaging } from '@angular/fire/messaging';
imports: [
provideFirebaseApp(() => initializeApp(environment.firebase)),
provideAuth(() => {
if (Capacitor.isNativePlatform()) {
return initializeAuth(getApp(), {
persistence: indexedDBLocalPersistence
});
} else {
return getAuth()
}
}),
provideMessaging(() => getMessaging()),
provideStorage(() => getStorage()),
] And for exemple in my auth service you need to do something like that: import { Auth, signInWithEmailAndPassword } from '@angular/fire/auth';
@Injectable({
providedIn: 'root'
})
export class AuthService {
constructor(
private afAuth: Auth,
){}
signinWithEmailAndPasswordd(email: string, password: string) {
return signInWithEmailAndPassword(this.afAuth, email, password);
}
} |
@bocodigital I can't find that code. Weird. I know I did it. |
@donhmorris and @rodrigoreal right now my firebsase and firestore services are using compat. Can I mix them? |
@bocodigital idk man, i dont think so, i was also using compat, but i migrated it to modular when i upgraded to firebase 9 and i only discovered this problem after, so i cant help you to fix that with compat. |
@rodrigoreal @donhmorris I got it working with a combo of compat and modular. I will just port the whole thing to modular. I don't see the point of angular fire though since firebase v9 has everything you need. |
I can confirm @rodrigoreal solution is working but the app must use angular fire 7 APIs. |
This also resolved my issue, still can't found an official bug on this. |
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:
|
using firebase 9.8.4 worked |
@MaxLeggieri I believe I read on the Firebase GitHub that this was expected behavior and your code example is the correct implementation so they chose not to open a bug report. This worked for me as well btw. |
the provideAuth() implementation also solved my issue. Can't believe this isn't mentioned in the docs. I wasted weeks on this! |
In case anyone is using Bootstrapped components In your main.ts
|
Thank you so much for posting this. I am now able to get past this blocker. |
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
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
The text was updated successfully, but these errors were encountered: