首页 > 解决方案 > React-Native Google-SignIn 注销不起作用

问题描述

我有个问题。当我登录我的应用程序并刷新时,我去尝试注销,我必须手动刷新才能看到我已注销。基本上发生的情况是,它卡在了我的 try catch 语句中,因此我什么也看不到,但如果我刷新,我就会很好地注销。但是,如果我从中删除await关键字GoogleSignIn.revokeAcess()并且GoogleSignin.signOut()它按预期工作。文档显示了一个示例,他们正在使用等待。删除等待对我来说是不好的做法吗?提前致谢。

代码:

export function logout(): ThunkResult<void> {
  return function(dispatch) {
    Keychain.resetGenericPassword().then(async () => {
      amplitude.logEvent('Log out');
      LoginManager.logOut();
      try {
        const isSignedIn = await GoogleSignin.isSignedIn();
        if (isSignedIn) {
          console.log('gets here'); // LOGS THIS
          await GoogleSignin.revokeAccess(); // GETS STUCK HERE
          console.log('passed revoke access'); // doesn't log this
          await GoogleSignin.signOut();
          console.log('passed signOut');
        }
      } catch (err) {
        console.log(err);
        amplitude.logEvent('Failed Google Logout', err);
      }
      console.log('passes');
      resetAllPreferences();
      dispatch(postLogout());
      dispatch(fetchMoreActivities());
    });
  };
}

接着

const mapDispatchToProps = (dispatch: AsyncDispatch) => ({
  synchronizeReads: () => dispatch(synchronizeReadInsights()),
  logout: () => dispatch(logout()), // here i take the action above from my actions file
});

并像使用它一样

const onLogoutPress = async () => {
  await synchronizeReads();
  logout();
  Navigation.pop(componentId);
};

标签: reactjsreact-nativegoogle-signin

解决方案


推荐阅读