[英]Firebase Authentication Sticks Capacitor Ionic on iOS
I am using angular-fire for firebase authentication on Ionic-Capacitor.我在 Ionic-Capacitor 上使用 angular-fire 进行 firebase 身份验证。 It works fine on the web and android, but not on IOS.
它在 web 和 android 上运行良好,但在 IOS 上运行良好。
When I inspected the app.network activity, I realized the app is able to get an Authentication response successfully from firebase, but it's not fulfilling the async call.当我检查 app.network 活动时,我意识到该应用能够从 firebase 成功获得身份验证响应,但它没有完成异步调用。
My app.module.ts我的 app.module.ts
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot({mode: 'ios'}), AppRoutingModule,
HttpClientModule,
AngularFireModule.initializeApp(environment.firebaseConfig),
AngularFireAuthModule,
AngularFirestoreModule
]})
This is how I am initializing Angular fire.这就是我初始化 Angular fire 的方式。
This is a FirebasePlugin issue.这是一个 FirebasePlugin 问题。 All you need to do is to initialize AngularFire with the latest method.
您需要做的就是用最新的方法初始化 AngularFire。
OLD Method (Wrong) -旧方法(错误)-
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot({mode: 'ios'}), AppRoutingModule,
HttpClientModule,
AngularFireModule.initializeApp(environment.firebaseConfig),
AngularFireAuthModule,
AngularFirestoreModule
]})
Working Method (NEW)工作方法(新)
import {getApp, initializeApp, provideFirebaseApp} from "@angular/fire/app";
import {getAuth, initializeAuth, provideAuth, indexedDBLocalPersistence} from "@angular/fire/auth";
@NgModule({
imports: [
provideFirebaseApp(() => initializeApp(environment.firebaseConfig)),
provideAuth(() => {
if (Capacitor.isNativePlatform()) {
return initializeAuth(getApp(), {
persistence: indexedDBLocalPersistence
})
} else {
return getAuth()
}
})]
})
After modifying the initializing approach, you'll need to remove usage of AngularFireAuth, instead use it like:-修改初始化方法后,您需要删除 AngularFireAuth 的使用,而不是像这样使用它:-
import {Auth, createUserWithEmailAndPassword, signInWithEmailAndPassword} from "@angular/fire/auth";
export class UserService {
constructor(private auth : Auth) {
const user: any = await signInWithEmailAndPassword(this.auth,email,password);
}
Also, you can visit the latest docs of AngularFire to understand it better.此外,您可以访问 AngularFire 的最新文档以更好地理解它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.