javascript - Firebase 在 onAuthStateChange 之后获取子级但出现错误客户端处于脱机状态
问题描述
使用firebase onAuthStateChange后如何在实时数据库中获取用户实例?
我在我的 useEffect 中尝试过这样的操作,但出现错误Client is Offline
我很确定我的连接良好,firebase 也在线
Btw 如果我删除get(child())代码,代码正在工作
我需要这个 get child用于获取用户实例以将用户数据存储到初始屏幕内的本地存储
注意:Firebase v9.1.1 + React Native 0.66.0
useEffect(() => {
const auth = getAuth(Firebase);
const dbRef = ref(getDatabase(Firebase));
const unsubscribe = navigation.addListener('focus', () => {
onAuthStateChanged(auth, user => {
setTimeout(() => {
if (user) {
console.log('Logged => ', user);
get(child(dbRef, `users/${user.uid}`)).then(snapshot => {
if (snapshot.val()) {
console.log('User In Db...');
storeLocalStorage('user', snapshot.val());
navigation.replace('MainApp');
} else {
console.log('User Not In DB..');
removeLocalStorage('user');
navigation.replace('GetStarted');
}
});
} else {
console.log('Not Logged In');
removeLocalStorage('user');
navigation.replace('GetStarted');
}
}, 3000);
});
});
return unsubscribe;
}, [navigation]);
解决方案
推荐阅读
- php - php如何表示浮点数
- asp.net-core - 使用 Ocelot 为 Web 套接字连接设置 CORS 策略
- java - 类路径包含多个 SLF4J 绑定 - 我没有找到加倍的条目
- r - 在ggplotly生成的工具提示中抑制变量名称
- mysql - 使用映射自定义子域时,Google Cloud Run 失去了与 Mysql 的连接
- amazon-web-services - aws如何管理对ec2的iam ssh访问
- flutter - Flutter widget that scales it's child before laying it out?
- amazon-web-services - Error in Call to Sagemaker Endpoint with Lambda and API Gateway
- ios - 我怎样才能提高它的性能......为什么没有 LazyZStack 这样的东西?
- firebase - 如何在 Firestore 集合中检索文档的 documentId,以便在返回对象流的 getter 中使用它