为什么Firebase注销后会引发权限错误?

时间:2020-04-14 22:45:24

标签: firebase react-native firebase-authentication

在本地本机应用程序中,调度一个调用firebase-auth的操作以退出登录会导致firebase权限错误:

enter image description here

这是派发动作的抽屉组件内部的方法:

logout = () => {
        this.props
            .logoutUser()
            .then(() => {
                this.props.navigation.navigate('Login');
            })
            .catch((err) => alert(err));
    };

这是logout操作:

export const logoutUser = () => {
    return (dispatch) => {
        return new Promise((resolve, reject) => {
            firebase
                .auth()
                .signOut()
                .then(() => {
                    dispatch({ type: types.RESET_APP });
                    console.log('Dispatching types.RESET_APP');
                    resolve();
                })
                .catch((error) => reject(error.message));
        });
    };
};

执行后,屏幕将根据需要返回到登录屏幕。控制台记录Dispatching types.RESET_APP,然后显示以上错误。

我的登录名中的authStateChanged侦听器:

export const loginUser = (email, password) => {
    return (dispatch) => {
        dispatch({ type: types.LOGIN_USER });
        // listen for change in auth state before signing in
        return new Promise((resolve, reject) => {
            firebase
                .auth()
                .signInWithEmailAndPassword(email, password)
                .then((userCredential) => {
                    console.log('User Credential: ' + JSON.stringify(userCredential));
                    const unsubscribe = firebase.auth().onAuthStateChanged((user) => {
                        if (user) {
                            console.log('Logged in: ' + user.email);
                            loginUserSuccess(dispatch, user);
                            resolve(user);
                        } else {
                            console.log('Authentication state changed, user object is null...');
                            //resetAuth();
                        }
                    });
                    // No longer need to listen to auth state
                    unsubscribe();
                })
                .catch((error) => {
                    console.log('Error during Email sign-in: ' + error);
                    loginUserFail(dispatch, error.message);
                });
        });
    };
};

身份验证状态观察者未在登录功能中取消订阅,那是什么原因引起的?

0 个答案:

没有答案