Answer the question
In order to leave comments, you need to log in
How to reload a window in ReactNative?
How to reload the window when everything went well
const loginHandler = () => {
fetch('http://192.168.0.21:3001/auth/login', {
method: 'POST',
body: JSON.stringify({ ...form }),
headers: {
Accept: '*/*',
'Content-Type': 'application/json',
},
})
.then((res) => res.json())
.then((res) => {
if (res.message === 'Успешно зашли!') {
console.log('Успешно!');
Alert.alert('Успешно!');
} else if (res.message === 'Пароль неверный!') {
console.log('Пароль неверный!');
Alert.alert('Пароль неверный!');
} else if (res.message === 'Такого пользователя нету!') {
console.log('Такого пользователя нету!');
Alert.alert('Такого пользователя нету!');
}
});
};
// Это главный компонент мой где при загрузке узнаем пользователь залогинен или нет
export const Application = () => {
const [user, setUser] = useState({});
setStatusBarStyle({
color: '#000',
});
useEffect(async () => {
const fetchAuth = async () => {
await fetch('http://192.168.0.21:3001/auth/check-user')
.then((res) => res.json())
.then((res) => setUser(res));
};
fetchAuth();
}, []);
console.log(user);
if (user.login) {
return (
<View style={styles.app}>
<AppHeader />
<AppNavigator>
<StatusBar hidden style="auto" />
</AppNavigator>
</View>
);
}
return <AuthNavigator />;
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question