簡體   English   中英

如何在firestore中離線時登錄

[英]How to log in whilst offline in firestore

如我的 app.ts 上的文檔中所示,我已啟用 Persistence()。

import { AngularFirestoreModule } from '@angular/fire/firestore';
 imports: [ AngularFirestoreModule.enablePersistence()]

一旦我登錄並斷開我的網絡,該應用程序在離線模式下運行良好,並且在重新連接網絡時它會消失。

我的登錄 function 是:

  async login() {
          await this.presentLoadings();
            const { email, password } = this
            try { 

              const res = await this.afAuth.auth.signInWithEmailAndPassword(email , password)

              if(res.user) {
                this.user.setUser({
                  email,
                  password,
                  uid: res.user.uid
                })
                this.router.navigate(['/tabs/dashboard'])
              }

            } catch(err) {
              this.presentToast(err.message);
            }
            finally
            {
              this.loading.dismiss();
            }
          }

沒有互聯網連接就無法登錄新用戶。

也就是說,如果用戶之前登錄過,Firebase 身份驗證將在應用程序重新啟動時自動恢復他們的身份驗證 state,並且在沒有網絡連接時起作用。

要檢測此自動登錄, 請使用onAuthStateChange偵聽器

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User is signed in, so set the state, and navigate to the dashboard.
  } else {
    // No user is signed in.
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM