Skip to content

Instantly share code, notes, and snippets.

@iiagodias
Created February 14, 2019 13:35
Show Gist options
  • Save iiagodias/c5c00b921a8151f589f00fe1f2f25e8b to your computer and use it in GitHub Desktop.
Save iiagodias/c5c00b921a8151f589f00fe1f2f25e8b to your computer and use it in GitHub Desktop.
async logar(email, senha, token, tipo){
try {
if(email == ""){
Alert.alert("Aviso", "Preencha o campo e-mail.");
}else if(senha == ""){
Alert.alert("Aviso", "Preencha o campo senha.");
}else{
this.setState({loading: true});
const response = await fetch(`https://www.buscabelem.com.br/api/cadastro_login.php?login=${email}&senha=${senha}&token=${token}&tipo=${tipo}`);
const result = await response.json();
if(result.status){
this.setState({loading: false});
await AsyncStorage.setItem("@BuscaBelem:usuario", JSON.stringify(result));
this.props.navigation.dispatch(resetAction);
}else{
this.setState({loading: false});
Alert.alert("Aviso", "E-mail e senha incorreto.");
}
}
} catch (error) {
this.setState({loading: false});
Alert.alert("Erro", "Erro na conexão.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment