保存自动连接到firebase react本机redux应用程序的用户名和密码

保存自动连接到firebase react本机redux应用程序的用户名和密码,firebase,react-native,redux,firebase-authentication,redux-thunk,Firebase,React Native,Redux,Firebase Authentication,Redux Thunk,我正在为IOS构建React native/Redux thunk/Firebase应用程序。这是我的app.js的一部分 { this.props.data.userConnected==false? <View style={styles.container1}> <Login/> </View> :null } { this.props.data.userConnected==true?

我正在为IOS构建React native/Redux thunk/Firebase应用程序。这是我的app.js的一部分

  {
    this.props.data.userConnected==false?
    <View style={styles.container1}>
    <Login/>
    </View>

  :null
  }
  {
    this.props.data.userConnected==true?
    <View style={styles.container1}>
    <Connected/>
    </View>
  :null
  } 
{
this.props.data.userConnected==false?
:null
}
{
this.props.data.userConnected==true?
:null
} 
当用户单击login时,我正在使用firebase.auth函数,如果连接成功,我将在redux存储中将变量userConnected设置为true。我的问题是,大约3小时后,我的用户被断开连接,变量userConnected被设置为false,因为它是初始值

我真的不知道该怎么办,因为我在想redux商店不能再次初始化,除非关闭并重新打开应用程序


提前感谢您的建议。

您可以保存从firebase返回的会话令牌和刷新令牌,并将其添加到redux persist。每次应用程序进入后台时,您都可以检查并重新打开,您需要检查会话令牌是否过期。如果是,请使用刷新令牌重新生成并保存返回值。有关更多信息,请查看

您可以保存会话令牌和从firebase返回的刷新令牌,并将其添加到redux persist。每次应用程序进入后台时,您都可以检查并重新打开,您需要检查会话令牌是否过期。如果是,请使用刷新令牌重新生成并保存返回值。有关更多信息,请查看

我使用react本地存储解决了问题

首先,我使用以下内容导入包装:

import ls from 'react-native-local-storage';
当用户首次登录时,在传递firebase.auth(电子邮件、密码)后,我会使用以下命令将信息写入iphone的本地存储:

        ls.save('email', email)
        .then(() => {
          ls.get('email').then((data) => {console.log("get: ", data)});
          // output should be "get: Kobe Bryant"
        })


       ls.save('password', password)
        .then(() => {
          ls.get('password').then((data) => {console.log("get: ", data)});
          // output should be "get: Kobe Bryant"
        })
然后,在我的应用程序组件的componentWillMount功能中,我通过以下方式获取用户的电子邮件和密码:

   ls.get('email').then((email) => {
     if (email!=null){
        ls.get('password').then((password) => {
          console.log("password: ", password);
          console.log("email: ", email);
          this.props.initApp(3,email,'');
          this.props.initApp(4,'',password);
          this.props.initApp(1,email,password,this.props.data);
        });
      }
    });

获取数据后,我将调用我的redux操作,该操作调用firebase.auth(电子邮件,密码)。现在,只需设置我的react本机firebase应用程序的自动登录:)。

我使用react本机本地存储解决了我的问题

首先,我使用以下内容导入包装:

import ls from 'react-native-local-storage';
当用户首次登录时,在传递firebase.auth(电子邮件、密码)后,我会使用以下命令将信息写入iphone的本地存储:

        ls.save('email', email)
        .then(() => {
          ls.get('email').then((data) => {console.log("get: ", data)});
          // output should be "get: Kobe Bryant"
        })


       ls.save('password', password)
        .then(() => {
          ls.get('password').then((data) => {console.log("get: ", data)});
          // output should be "get: Kobe Bryant"
        })
然后,在我的应用程序组件的componentWillMount功能中,我通过以下方式获取用户的电子邮件和密码:

   ls.get('email').then((email) => {
     if (email!=null){
        ls.get('password').then((password) => {
          console.log("password: ", password);
          console.log("email: ", email);
          this.props.initApp(3,email,'');
          this.props.initApp(4,'',password);
          this.props.initApp(1,email,password,this.props.data);
        });
      }
    });
获取数据后,我将调用我的redux操作,该操作调用firebase.auth(电子邮件,密码)。现在,只需设置一个自动登录到我的react原生firebase应用程序:)