React native 当前环境不支持指定的持久性类型
web浏览器和React本机应用程序的默认值为本地(前提是浏览器支持此存储机制,例如启用了第三方cookie/数据),而Node.js后端应用程序的默认值为无 当我在我的React原生Android应用程序中尝试以下操作时:React native 当前环境不支持指定的持久性类型,react-native,firebase-authentication,react-native-android,React Native,Firebase Authentication,React Native Android,web浏览器和React本机应用程序的默认值为本地(前提是浏览器支持此存储机制,例如启用了第三方cookie/数据),而Node.js后端应用程序的默认值为无 当我在我的React原生Android应用程序中尝试以下操作时: const signIn = () => firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL).then(() => { return firebase.auth()
const signIn = () =>
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL).then(() => {
return firebase.auth().signInAnonymously();
});
我得到以下错误:
The current environment does not support the specified persistence type.
这是一个bug还是我从文档中漏掉了什么
环境:
"dependencies": {
"firebase": "^4.5.0",
"react": "16.0.0-alpha.12",
"react-native": "^0.48.4",
}
Android 7.0
选择性导入firebase模块时似乎存在错误。
从更改导入
import * as firebase from 'firebase/app';
import 'firebase/auth';
到
解决了问题。嘿,Prashanth,这是在4.2.0中发布的:您可以尝试降级到该版本,看看这是否是一种回归吗?降级到4.2.0并没有解决问题。添加
firebase.default.INTERNAL.extendNamespace({INTERNAL:{reactNative:{AsyncStorage:AsyncStorage}}})设置持久性之前的代码>会使错误消失,尽管在应用程序重新启动之间(每次都是不同的user.uid),身份验证仍然没有持久化。我找到了根本原因。我使用选择性导入,即从“firebase/app”导入“firebase/auth”
将导入*作为firebase。切换到从“firebase”导入firebase可解决此问题。酷。谢谢你的更新。我对v4.5.0也有同样的问题,但我已经用这种方式导入了。还有其他解决办法吗?从4.3升级后,登录用户不再被持久化。我建议通过在firebase js sdk repo中创建一个问题来进行后续操作:。让其他人知道什么对您有效,或者您是否找到了更好的解决方案。@roiekoper我在4.5.1中遇到了这个问题(已经在执行从“firebase”导入firebase的),并升级到4.6.0为我解决了这个问题
import firebase from 'firebase';