-
-
Save suissa/79c940a3fc7c77c5e53d635b2a51fbce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Login | |
async Api(){ | |
this.setState({loading: true}) | |
NetInfo.isConnected.addEventListener( | |
'connectionChange', | |
(isConnected) => this.setState({internet: isConnected}) | |
) | |
if(this.state.internet){ | |
try { | |
const res = await 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 (error) { | |
console.log(error) | |
} | |
// }) | |
// .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