javascript - firebase.auth().onAuthStateChanged 在每次选项卡更改时调用
问题描述
我正在使用带有 ionic 5 的 firebase。每次导航到另一个选项卡时,我都可以看到每次调用 firebase.auth().onAuthStateChanged。
我的代码是:
React.useEffect(() => {
isLogin();
}, []);
const isLogin = async () => {
var unsubscribe = firebase.auth().onAuthStateChanged(async (user) =>{
if (user) {
const store = new Storage();
await store.create();
const eventId = await store.get('eventId');
const sendSms = await store.get('sendSms');
const userContext: any = {
uid: user.uid,
eventId: eventId,
sendSms: sendSms,
};
setContext(userContext);
setShowLoader(false)
} else {
setShowLoader(false)
setContext(undefined);
}
});
}
return (
<Context.Provider value={[context, setContext]}>
<IonApp>
<IonLoading
cssClass='my-custom-class'
isOpen={showLoader}
message={'Please wait...'}
duration={5000}
/>
{context?.uid ?
<IonTabs>
<IonRouterOutlet>
<Route path='/tabs/guests' component={Dashboard} exact />
<Route path='/tabs/tables' component={Tables} exact />
<Route path='/tabs/settings' component={Settings} exact />
</IonRouterOutlet>
<IonTabBar slot='bottom'>
<IonTabButton tab='guests' href='tabs/guests'>
<IonLabel>אורחים</IonLabel>
</IonTabButton>
<IonTabButton tab='tables' href='tabs/tables'>
<IonLabel>שולחנות</IonLabel>
</IonTabButton>
<IonTabButton tab='settings' href='tabs/settings'>
<IonLabel>הגדרות</IonLabel>
</IonTabButton>
</IonTabBar>
</IonTabs>
: <LoginPage />}
</IonApp>
</Context.Provider>
)
您能帮我找出重复调用身份验证状态更改事件处理程序的原因吗?
解决方案
推荐阅读
- bevy - 如何在 Bevy 中围绕本地原点旋转 3d 网格
- postgresql - Amazon RDS 上的 PostgresSQL
- python - mysql没有插入正确的值
- python - 根据条件创建修改后的熊猫行副本的更好方法
- c# - 使用网络服务获取随机视频并播放。C# WPF
- arrays - 使用strtok在C中为这个结构分配空间的正确方法是什么
- css - pure-react-carousel 点我想显示在我的 div 滑动时移动的滚动条
- javascript - 如何使用 React Hooks 实现刷新按钮?
- sql - 基于列排除行
- html - 我将如何在容器中重叠复制这种设计?