Skip to content

Instantly share code, notes, and snippets.

@davit-khaburdzania
Created February 22, 2017 14:43
Show Gist options
  • Save davit-khaburdzania/a1d1663370d7b29a39ecb44e713734e2 to your computer and use it in GitHub Desktop.
Save davit-khaburdzania/a1d1663370d7b29a39ecb44e713734e2 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import { AsyncStorage } from 'react-native'
import request from 'axios'
import { NavigationProvider, StackNavigation } from '@exponent/ex-navigation'
import { connect } from 'react-redux'
import Router from 'app/routes'
import { UserActions } from 'app/store/actions'
import { UserSelectors } from 'app/store/selectors'
let connectProps = {...UserActions}
let connectState = state => ({ currentUser: UserSelectors.current(state) })
let enhancer = connect(connectState, connectProps)
class App extends Component {
componentWillMount () {
this.reAuthenticateUser()
}
async reAuthenticateUser () {
try {
let token = await AsyncStorage.getItem('auth_token')
if (!this.props.currentUser && token) {
request.defaults.headers.common['AUTH-TOKEN'] = token
this.props.getMe()
}
} catch (error) {}
}
render () {
let initialRoute = this.props.currentUser ? 'houses' : 'login'
return (
<NavigationProvider router={Router}>
<StackNavigation
defaultRouteConfig={{
navigationBar: {
backgroundColor: '#fff',
tintColor: '#000'
}
}}
initialRoute={Router.getRoute(initialRoute)}
/>
</NavigationProvider>
)
}
}
export default enhancer(App)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment