title: How do I manage user account state in react native and the facebook sdk?
body: <p>In my react native app I am handling user accounts through facebook. I have succesfully hooked up the Facebook SDK to my app and I am displaying the "Log in with Facebook" button successfully that when tapped lets the user log in with Facebook and changes the button text to "log out". If the user taps "logout" it logs them out and changes the text back to log in. Basically it seems I have the basic functionality of logging in and logging out working.</p>
  
  <p>I have a few questions though about how to do anything beyond this regarding the state of the user in terms of being logged in to facebook or not. </p>
  
  <p>For one, it seems the user's log in does not persist between app lifetimes. if i close the app and reopen it, it prompts me to log in again instead of remembering that I had just logged in and automatically logging me in with Facebook. Is there a way to tell it to do this/cache the log in easily via the FacebookSDK? I imagine there must be but the documentation by Facebook seems sparse on the subject.</p>
  
  <p>Furthermore, is there a way to check the state of the user right now via a boolean property or something that just says they are logged in or not. </p>
  
  <p>Below is my current code that is succesfully showing the Facebook login and log out button as well as handling the log in and log out flows.</p>
  
  <pre><code>/**
   * Sample React Native App
   * https://github.com/facebook/react-native
   * @flow
   */
  
  import React, { Component } from 'react';
  import {
    AppRegistry,
    StyleSheet,
    Text,
    View
  } from 'react-native';
  
  const FBSDK = require('react-native-fbsdk');
  const {
    LoginButton,
    AccessToken,
    GraphRequest,
    GraphRequestManager,
  } = FBSDK;
  
  export default class FBReact extends Component {
    render() {
      return (
        &lt;View&gt;
          &lt;Text style={styles.welcome}&gt;
            Welcome to React Native!
          &lt;/Text&gt;
          &lt;Text style={styles.instructions}&gt;
            To get started, edit index.ios.js
          &lt;/Text&gt;
          &lt;Text style={styles.instructions}&gt;
            Press Cmd+R to reload,{'\n'}
            Cmd+D or shake for dev menu
          &lt;/Text&gt;
          &lt;LoginButton
            publishPermissions={["publish_actions"]}
            onLoginFinished={
              (error, result) =&gt; {
                if (error) {
                  alert("login has error: " + result.error);
                } else if (result.isCancelled) {
                  alert("login is cancelled.");
                } else {
                  AccessToken.getCurrentAccessToken().then(
                    (data) =&gt; {
                      alert(data.accessToken.toString())
                    }
                  )
                }
              }
            }
            onLogoutFinished={() =&gt; alert("logout.")}
            onLogInFound={() =&gt; alert("log in found.")}/&gt;
        &lt;/View&gt;
      );
    }
  }
  
  
  AppRegistry.registerComponent('FBReact', () =&gt; FBReact);
  </code></pre>