簡體   English   中英

反應本機 firebase AsyncStorage 警告?

[英]React native firebase AsyncStorage warning?

我正在開發一個帶有 firebase 的 React Native expo 項目。我安裝了 firebase:“yarn add firebase”,當我使用 OnAuthChanged 導入 firebase/auth 時,出現以下錯誤:

AsyncStorage 已從 react-native 核心中提取出來,並將在未來的版本中刪除。 現在可以從“@react-native-async-storage/async-storage”而不是“react-native”安裝和導入它。 參見https://github.com/react-native-async-storage/async-storage

我知道 firebase 使用異步在本地存儲我的憑據並且它已經過時,這就是我收到此錯誤的原因。 現在,當我嘗試通過安裝來消除此錯誤時:“yarn add @react-native-async-storage/async-storage”並將 index.js 中的依賴項更改為正確的異步存儲 package ( https:// stackoverflow.com/a/70122024/15845974 )然后我的警告消失了。

現在的問題是我的憑據沒有保存,並且 onAuthChanges 永遠不會觸發。 每次打開我的應用程序時我都必須登錄。正確版本的異步存儲不會保存我的信用。

對此有什么想法嗎? :S

import { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';

const firebaseConfig = {
...
  };  

const firebaseApp = initializeApp(firebaseConfig);
const auth = getAuth(firebaseApp);

onAuthStateChanged(auth, user => {userHandler(user)});

此代碼為我刪除了 AsyncStorage 警告

import AsyncStorage from '@react-native-async-storage/async-storage';
import {initializeApp, getApps, getApp} from 'firebase/app';

import {
  initializeAuth,
  getReactNativePersistence,
} from 'firebase/auth/react-native';

const firebaseConfig = {
  // Configuration
};


const app = getApps().length === 0 ? initializeApp(firebaseConfig) : getApp();


const auth = initializeAuth(app, {
  persistence: getReactNativePersistence(AsyncStorage),
});

export {auth};

暫無
暫無

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

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