#react-native
#react-native
Вопрос:
Это простое приложение для входа в систему с помощью API и выхода из системы. Я извлек токен доступа при входе в систему. Я переместил маркер доступа на боковую панель и попытался выйти из системы с помощью функции выхода
SideBar.js
import React from 'react';
import { Text, Alert } from 'react-native';
import { Drawer,Container, Content, Header, Right, Button } from 'native-base';
export default class SideBar extends React.Component {
constructor(props) {
super(props)
this.state = {
token: this.props.usertoken
}
}
UserLogoutFunction = () =>{
const { token } = this.state;
fetch('https://api.idepoz.com/ncl/api/logout', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${token}`,
},
body: JSON.stringify({
})
}).then((response) => response.json())
.then((responseJson) => {
console.log("token");
if(responseJson)
{
this.props.navigation.navigate('Login');
Alert.alert("Succesfully Logged Out");
}
else{
Alert.alert(responseJson);
}
}).catch((error) => {
console.error(error);
});
}
render() {
return (
<Container>
<Header>
</Header>
<Content>
<Button transparent onPress={ this.UserLogoutFunction } >
<Text style={{fontSize: 24}}>Log Out</Text>
</Button>
</Content>
</Container>
);
}
}
Сбой при возврате СЕТЕВОГО ЗАПРОСА.
Приведенная ниже функция вернула маркер доступа при входе в систему
UserLoginFunction = () =>{
const { UserName } = this.state ;
const { UserPassword } = this.state ;
fetch('https://api.idepoz.com/ncl/api/login', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: UserName,
password: UserPassword
})
}).then((response) => response.json())
.then((responseJson) => {
if(responseJson)
{
this.props.navigation.navigate('QrScan',{usertoken:responseJson.token});
}
else{
Alert.alert(responseJson);
}
}).catch((error) => {
console.error(error);
});
}
Пожалуйста, скажите, что не так с «UserLogoutFunction»
Комментарии:
1. Можете ли вы предоставить более подробную информацию об ошибке «СБОЙ СЕТЕВОГО ЗАПРОСА», есть ли еще журналы? Какой код ошибки HTTP отображается?
2. @GabrielMenezesdaSilva — Пожалуйста, проверьте изображение и дайте решение, если это возможно.