reactjs - 无法使用 redux 从 firebase 身份验证中注销。用户会话仍然存在
问题描述
摘要:
我正在使用 firebase 进行身份验证。我正在尝试使用 firebase signout() 方法进行单选。注销后,用户使用 Actions.auth() 导航到登录场景。[auth 是我的登录表单场景名称]
问题:,
使用注销后,它会正确导航到登录屏幕。但是当我再次登录时,它显示我的空白屏幕。当我做任何活动时,例如在空白处触摸屏幕,数据就会再次出现。
我认为我做错了什么[显然哈哈]或者我错过了一些基本面。
寻求帮助。
我只需要用户注销并导航到登录屏幕。
1. 我在 types.js 中创建了动作
export const LOG_OUT_USER = 'log_out_user';
2. 我在 AuthActions.js 中创建了一个动作并在顶部 'LOG_OUT_USER' 上导入并添加如下代码
export const logOutUser = () => dispatch => {
firebase.auth()
.signOut()
.then(() => {
console.log('Sign-out successful');
dispatch({ type: LOG_OUT_USER });
Actions.auth();
})
.catch(error => {
console.log(error);
});
};
3. 在 AuthReducer.js 中我导入了 'LOG_OUT_USER' 并添加了如下案例
const INITIAL_STATE = {
email: '',
password: '',
user: null,
error: '',
loading: false
};
case LOG_OUT_USER:
return INITIAL_STATE;
4. 我在员工列表中添加了一个注销按钮。
//imported the action
import { employeesFetch, logOutUser } from '../actions';
//added function after 'componentWillReceiveProps' function
onButtonPressLogout() {
console.log('logout');
this.props.logOutUser();
}
//added card section with logout button
<CardSection>
<Button onPress={this.onButtonPressLogout.bind(this)}>
Log Out
</Button>
</CardSection>
//exported at the bottom
export default connect(mapStateToProps, { employeesFetch, logOutUser })(EmployeeList);
如果您想查看 repo:https ://github.com/hemantc09/react-native-Manager-Employee-App
只需下载并运行命令:- react-native run-ios
输出: 第一次登录:
注销后重新登录:显示 . 黑屏。我在控制台中看到即使注销后用户数据仍在打印。我在这里缺少什么。
如果您想使用 testflight 看看,请告诉我。我会给你发邀请函。
解决方案
推荐阅读
- mysql - MySQL将另一个表中的varchar行加入列
- java - 对于给定的场景,String 对象创建在 Java 中是如何工作的?
- java - 使用未初始化的变量时会发生什么类型的错误?
- django - 如何在 ManyToMany Django 中获取数据并在 view.py 中渲染
- angularjs - 可以在同一个应用程序中使用 AngularJs 和 Angular (v7) 吗?
- types - 什么是`init : () -> (Model, Cmd Msg)`注解?
- mysql - docker上的nextcloud和mariadb(两者):SQLSTATE [HY000] [2002]没有这样的文件或目录
- google-sheets - 未显示的公式引用数据
- php - 正则表达式获取字符串中的数字
- mysql - 搜索性能 mysql