简体   繁体   English

Firebase 认证棒电容 Ionic on iOS

[英]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.

相关问题 Firebase 身份验证如何与离子和电容器一起使用? - How does firebase authentication work with ionic and capacitor? Firebase 动态链接不适用于带电容器的 ios - Firebase Dynamic links not working for ios with capacitor Ionic / Angular / Capacitor / Firebase Facebook 基于身份验证和角色的身份验证 - Ionic / Angular / Capacitor / Firebase Facebook Auth & role based authentification Ionic Capacitor firebase 推送通知,报错:Default FirebaseApp is not initialized in this process - Ionic Capacitor firebase push notification, error:Default FirebaseApp is not initialized in this process FCM 推送通知在使用离子电容器的 IOS 中不起作用 - FCM Push Notification are not working in IOS using Ionic Capacitor Firebase 插件不适用于 IOS (Ionic) - Firebase Plugins not Working on IOS (Ionic) Azure AD B2C 登录 Firebase Auth Capacitor 插件:Ionic/Angular - Azure AD B2C login with Firebase Auth Capacitor plugin: Ionic/Angular IONIC 6 电容器 Android & iOS 应用程序和 Azure AD 授权在外部浏览器中打开 - IONIC 6 Capacitor Android & iOS app and Azure AD auth open in external browser 电话号码身份验证不适用于 IOS 设备 [Firebase] - Authentication of phone number is not working on IOS Devices [Firebase] 我如何限制 ionic 和 firebase-authentication 中的页面 - how do i restrict pages in ionic and firebase-authentication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM