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

logout when session end

parent 113cb583
...@@ -50,6 +50,7 @@ const Login = (props) => { ...@@ -50,6 +50,7 @@ const Login = (props) => {
}; };
useEffect(() => { useEffect(() => {
props.hideLoading();
getAccount(); getAccount();
getTokenDevice(); getTokenDevice();
}, []); }, []);
......
import KEY from '../assets/AsynStorage'; import KEY from '../assets/AsynStorage';
import axios from 'axios'; import axios from 'axios';
import AsyncStorage from '@react-native-community/async-storage'; 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; axios.defaults.timeout = 10000;
...@@ -22,8 +25,22 @@ export async function GetData(url, data) { ...@@ -22,8 +25,22 @@ export async function GetData(url, data) {
}; };
console.log('My request', myRequest); console.log('My request', myRequest);
return await axios(myRequest) return await axios(myRequest)
.then((response) => response) .then((response) => {
.then((response) => 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) => { .catch((error) => {
console.log(error.request); console.log(error.request);
const err = { const err = {
...@@ -47,8 +64,22 @@ export async function PostLogin(url, json) { ...@@ -47,8 +64,22 @@ export async function PostLogin(url, json) {
}; };
console.log('post data mobile', myRequest); console.log('post data mobile', myRequest);
return await axios(myRequest) return await axios(myRequest)
.then((response) => response) .then((response) => {
.then((response) => 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) => { .catch((error) => {
console.log(error); console.log(error);
const err = { const err = {
...@@ -75,8 +106,22 @@ export async function PostData(url, json, isAuth = true) { ...@@ -75,8 +106,22 @@ export async function PostData(url, json, isAuth = true) {
}; };
console.log('post data mobile', myRequest); console.log('post data mobile', myRequest);
return await axios(myRequest) return await axios(myRequest)
.then((response) => response) .then((response) => {
.then((response) => 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) => { .catch((error) => {
console.log(error.request); console.log(error.request);
const err = { const err = {
...@@ -111,11 +156,21 @@ export async function PostFormData(url, data) { ...@@ -111,11 +156,21 @@ export async function PostFormData(url, data) {
return await axios(myRequest) return await axios(myRequest)
.then((response) => { .then((response) => {
clearTimeout(timeout); clearTimeout(timeout);
if (response.data?.code === 401) {
logout();
return;
} else {
return response; return response;
}
}) })
.then((response) => { .then((response) => {
clearTimeout(timeout); clearTimeout(timeout);
if (response.data?.code === 401) {
logout();
return;
} else {
return response; return response;
}
}) })
.catch((error) => { .catch((error) => {
clearTimeout(timeout); clearTimeout(timeout);
...@@ -148,8 +203,22 @@ export async function PutData(url, json, isAuth = true) { ...@@ -148,8 +203,22 @@ export async function PutData(url, json, isAuth = true) {
}; };
console.log('PutData', myRequest); console.log('PutData', myRequest);
return await axios(myRequest) return await axios(myRequest)
.then((response) => response) .then((response) => {
.then((response) => 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) => { .catch((error) => {
console.log(error.request); console.log(error.request);
const err = { const err = {
...@@ -159,3 +228,8 @@ export async function PutData(url, json, isAuth = true) { ...@@ -159,3 +228,8 @@ export async function PutData(url, json, isAuth = true) {
return err; return err;
}); });
} }
export function logout() {
showAlert(TYPE.ERROR, I18n.t('Notification'), I18n.t('LoginSessionEnd'));
DeviceEventEmitter.emit('logout');
}
...@@ -289,4 +289,5 @@ export default { ...@@ -289,4 +289,5 @@ export default {
WarnMinReqestWithdraw: WarnMinReqestWithdraw:
'The withdrawal amount must be more than 1 million dong', 'The withdrawal amount must be more than 1 million dong',
Overtime: 'Overtime OTP', Overtime: 'Overtime OTP',
LoginSessionEnd: 'Login session end, please login again',
}; };
...@@ -289,4 +289,5 @@ export default { ...@@ -289,4 +289,5 @@ export default {
FirstEscrow: 'Ký quỹ ban đầu (VNĐ) ', FirstEscrow: 'Ký quỹ ban đầu (VNĐ) ',
WarnMinReqestWithdraw: 'Số tiền rút phải lớn hơn 1 triệu đồng', 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', 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 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 {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import Icon from 'react-native-vector-icons/FontAwesome5'; import Icon from 'react-native-vector-icons/FontAwesome5';
import Ionicons from 'react-native-vector-icons/Ionicons'; import Ionicons from 'react-native-vector-icons/Ionicons';
...@@ -23,7 +23,7 @@ import {changeLanguage} from '../actions/language'; ...@@ -23,7 +23,7 @@ import {changeLanguage} from '../actions/language';
import KEY from '../assets/AsynStorage'; import KEY from '../assets/AsynStorage';
import AsyncStorage from '@react-native-community/async-storage'; import AsyncStorage from '@react-native-community/async-storage';
import {DETAILNEW} from '../routers/ScreenNames'; import {DETAILNEW} from '../routers/ScreenNames';
import {getHeight, getWidth} from '../Config/Functions'; import {getHeight, getWidth, logout} from '../Config/Functions';
const Tab = createBottomTabNavigator(); const Tab = createBottomTabNavigator();
...@@ -40,14 +40,25 @@ const TabNavigator = (props) => { ...@@ -40,14 +40,25 @@ const TabNavigator = (props) => {
setTimeout(() => { setTimeout(() => {
showPopUp(); showPopUp();
}, 3000); }, 3000);
let logoutListener = DeviceEventEmitter.addListener('logout', (e) => {
console.log('run in to logout');
logout(navigate);
});
return () => {
logoutListener.remove();
};
}, []); }, []);
const checkDeepking = () => { const checkDeepking = () => {
Linking.getInitialURL().then((url) => { Linking.getInitialURL().then((url) => {
if (url) deeplinkScreen(url); if (url) {
deeplinkScreen(url);
}
}); });
Linking.addEventListener('url', (url) => { Linking.addEventListener('url', (url) => {
if (url) handleOpenURL(url); if (url) {
handleOpenURL(url);
}
}); });
}; };
...@@ -78,7 +89,9 @@ const TabNavigator = (props) => { ...@@ -78,7 +89,9 @@ const TabNavigator = (props) => {
const setInitLanguage = async () => { const setInitLanguage = async () => {
const laguage = await AsyncStorage.getItem(KEY.LANGUAGE); const laguage = await AsyncStorage.getItem(KEY.LANGUAGE);
if (laguage) props.changeLanguage(laguage); if (laguage) {
props.changeLanguage(laguage);
}
setLocation(I18n, laguage); setLocation(I18n, laguage);
}; };
...@@ -104,7 +117,7 @@ const TabNavigator = (props) => { ...@@ -104,7 +117,7 @@ const TabNavigator = (props) => {
options={{ options={{
tabBarLabel: 'Overview', tabBarLabel: 'Overview',
tabBarIcon: ({color, size}) => ( tabBarIcon: ({color, size}) => (
<Icon name="landmark" size={size} color={color} /> <Icon name="landmark" size={size} color={color}/>
), ),
}} }}
/> />
...@@ -128,7 +141,7 @@ const TabNavigator = (props) => { ...@@ -128,7 +141,7 @@ const TabNavigator = (props) => {
name="Pay" name="Pay"
component={PayScreenComponent} component={PayScreenComponent}
options={{ options={{
tabBarButton: () => <PlussModal />, tabBarButton: () => <PlussModal/>,
}} }}
/> />
...@@ -153,7 +166,7 @@ const TabNavigator = (props) => { ...@@ -153,7 +166,7 @@ const TabNavigator = (props) => {
options={{ options={{
tabBarLabel: props.language.language == 'vi' ? 'Tin tức' : 'News', tabBarLabel: props.language.language == 'vi' ? 'Tin tức' : 'News',
tabBarIcon: ({color, size}) => ( 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