Skip to content

Instantly share code, notes, and snippets.

@rafaelaugustos
Created March 9, 2018 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rafaelaugustos/85f8f839fa759d6312f9b4c06616bb2f to your computer and use it in GitHub Desktop.
Save rafaelaugustos/85f8f839fa759d6312f9b4c06616bb2f to your computer and use it in GitHub Desktop.
// Login
Api(){
this.setState({loading: true})
NetInfo.isConnected.addEventListener(
'connectionChange',
(isConnected) => this.setState({internet: isConnected})
)
if(this.state.internet){
axios.post('https://localhost:8000/api/appcompras/login', {
scheme_url: 'namine',
email: this.state.email,
password: this.state.senha
})
.then(res => {
console.log(res)
this.setState({loading: false})
if(res.data.result.success){
this.setState({error: false})
AsyncStorage.setItem('@MySuperStore:dados', JSON.stringify(res.data))
AsyncStorage.setItem('@MySuperStore:token', "true")
Actions.catalogo({})
}else{
this.setState({error: false})
Toast.show({
text: res.data.result.message,
position: 'bottom',
buttonText: 'Okay'
})
}
})
.catch(err => console.log(err))
}else{
this.setState({loading: false})
Toast.show({
text: 'Sem conexão',
position: 'bottom',
buttonText: 'Okay'
})
}
}
// Catalogo
componentDidMount(){
console.log(AsyncStorage.getItem('@MySuperStore:dados'))
this.loadCatalogos()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment