Commit 9f568dc5 by Nguyễn Thị Thúy

logout when session end

parent 113cb583
......@@ -50,6 +50,7 @@ const Login = (props) => {
};
useEffect(() => {
props.hideLoading();
getAccount();
getTokenDevice();
}, []);
......
import KEY from '../assets/AsynStorage';
import axios from 'axios';
import AsyncStorage from '@react-native-community/async-storage';
import {showAlert, TYPE} from '../components/DropdownAlert/index';
import I18n from '../helper/i18/i18n';
import {DeviceEventEmitter} from 'react-native';
axios.defaults.timeout = 10000;
......@@ -22,8 +25,22 @@ export async function GetData(url, data) {
};
console.log('My request', myRequest);
return await axios(myRequest)
.then((response) => response)
.then((response) => response)
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.catch((error) => {
console.log(error.request);
const err = {
......@@ -47,8 +64,22 @@ export async function PostLogin(url, json) {
};
console.log('post data mobile', myRequest);
return await axios(myRequest)
.then((response) => response)
.then((response) => response)
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.catch((error) => {
console.log(error);
const err = {
......@@ -75,8 +106,22 @@ export async function PostData(url, json, isAuth = true) {
};
console.log('post data mobile', myRequest);
return await axios(myRequest)
.then((response) => response)
.then((response) => response)
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.catch((error) => {
console.log(error.request);
const err = {
......@@ -111,11 +156,21 @@ export async function PostFormData(url, data) {
return await axios(myRequest)
.then((response) => {
clearTimeout(timeout);
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.then((response) => {
clearTimeout(timeout);
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.catch((error) => {
clearTimeout(timeout);
......@@ -148,8 +203,22 @@ export async function PutData(url, json, isAuth = true) {
};
console.log('PutData', myRequest);
return await axios(myRequest)
.then((response) => response)
.then((response) => response)
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.catch((error) => {
console.log(error.request);
const err = {
......@@ -159,3 +228,8 @@ export async function PutData(url, json, isAuth = true) {
return err;
});
}
export function logout() {
showAlert(TYPE.ERROR, I18n.t('Notification'), I18n.t('LoginSessionEnd'));
DeviceEventEmitter.emit('logout');
}
......@@ -289,4 +289,5 @@ export default {
WarnMinReqestWithdraw:
'The withdrawal amount must be more than 1 million dong',
Overtime: 'Overtime OTP',
LoginSessionEnd: 'Login session end, please login again',
};
......@@ -289,4 +289,5 @@ export default {
FirstEscrow: 'Ký quỹ ban đầu (VNĐ) ',
WarnMinReqestWithdraw: 'Số tiền rút phải lớn hơn 1 triệu đồng',
Overtime: 'Mã OTP hết hạn sử dụng',
LoginSessionEnd: "Hết phiên đăng nhập, vui lòng đăng nhập lại",
};
import React, {useEffect} from 'react';
import {View, Text, Linking, Image} from 'react-native';
import {View, Text, Linking, Image, DeviceEventEmitter} from 'react-native';
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import Icon from 'react-native-vector-icons/FontAwesome5';
import Ionicons from 'react-native-vector-icons/Ionicons';
......@@ -23,7 +23,7 @@ import {changeLanguage} from '../actions/language';
import KEY from '../assets/AsynStorage';
import AsyncStorage from '@react-native-community/async-storage';
import {DETAILNEW} from '../routers/ScreenNames';
import {getHeight, getWidth} from '../Config/Functions';
import {getHeight, getWidth, logout} from '../Config/Functions';
const Tab = createBottomTabNavigator();
......@@ -40,14 +40,25 @@ const TabNavigator = (props) => {
setTimeout(() => {
showPopUp();
}, 3000);
let logoutListener = DeviceEventEmitter.addListener('logout', (e) => {
console.log('run in to logout');
logout(navigate);
});
return () => {
logoutListener.remove();
};
}, []);
const checkDeepking = () => {
Linking.getInitialURL().then((url) => {
if (url) deeplinkScreen(url);
if (url) {
deeplinkScreen(url);
}
});
Linking.addEventListener('url', (url) => {
if (url) handleOpenURL(url);
if (url) {
handleOpenURL(url);
}
});
};
......@@ -78,7 +89,9 @@ const TabNavigator = (props) => {
const setInitLanguage = async () => {
const laguage = await AsyncStorage.getItem(KEY.LANGUAGE);
if (laguage) props.changeLanguage(laguage);
if (laguage) {
props.changeLanguage(laguage);
}
setLocation(I18n, laguage);
};
......@@ -104,7 +117,7 @@ const TabNavigator = (props) => {
options={{
tabBarLabel: 'Overview',
tabBarIcon: ({color, size}) => (
<Icon name="landmark" size={size} color={color} />
<Icon name="landmark" size={size} color={color}/>
),
}}
/>
......@@ -128,7 +141,7 @@ const TabNavigator = (props) => {
name="Pay"
component={PayScreenComponent}
options={{
tabBarButton: () => <PlussModal />,
tabBarButton: () => <PlussModal/>,
}}
/>
......@@ -153,7 +166,7 @@ const TabNavigator = (props) => {
options={{
tabBarLabel: props.language.language == 'vi' ? 'Tin tức' : 'News',
tabBarIcon: ({color, size}) => (
<Ionicons name="newspaper-outline" size={size} color={color} />
<Ionicons name="newspaper-outline" size={size} color={color}/>
),
}}
/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment