Bug fix
This commit is contained in:
@@ -7,6 +7,7 @@ import { useSelector } from 'react-redux';
|
||||
import { _map } from './RN-UI-LIB/src/utlis/common';
|
||||
import { GenericType } from './src/common/GenericTypes';
|
||||
import Widget from './src/components/form';
|
||||
import { registerNavigateAndDispatch } from './src/components/utlis/apiHelper';
|
||||
import { setGlobalUserData } from './src/constants/Global';
|
||||
import { useAppDispatch } from './src/hooks';
|
||||
import useFirestoreUpdates from './src/hooks/useFirestoreUpdates';
|
||||
@@ -54,6 +55,8 @@ const ProtectedRouter = () => {
|
||||
}
|
||||
});
|
||||
|
||||
registerNavigateAndDispatch(dispatch);
|
||||
|
||||
return (
|
||||
<Stack.Navigator>
|
||||
{isLoggedIn ? (
|
||||
|
||||
@@ -43,6 +43,16 @@ API_URLS[ApiKeys.IMAGE_SIGNED_URLS] = '/cases/get-signed-urls';
|
||||
|
||||
const MOCK_API_URLS: Record<ApiKeys, string> = {} as Record<ApiKeys, string>;
|
||||
|
||||
export const API_STATUS_CODE = {
|
||||
OK: 200,
|
||||
CREATED: 201,
|
||||
BAD_REQUEST: 400,
|
||||
UNAUTHORIZED: 401,
|
||||
FORBIDDEN: 403,
|
||||
NOT_FOUND: 404,
|
||||
INTERNAL_SERVER_ERROR: 500
|
||||
};
|
||||
|
||||
let dispatch: Dispatch<any>;
|
||||
|
||||
const getErrorMessage = (err: any) => {
|
||||
@@ -163,7 +173,7 @@ axiosInstance.interceptors.response.use(
|
||||
});
|
||||
}
|
||||
|
||||
if (response.status === 401) {
|
||||
if ([API_STATUS_CODE.UNAUTHORIZED, API_STATUS_CODE.FORBIDDEN].includes(response.status)) {
|
||||
// Reset user info
|
||||
dispatch &&
|
||||
dispatch(
|
||||
@@ -192,9 +202,8 @@ axiosInstance.defaults.headers.common['Content-Type'] = 'application/json';
|
||||
axiosInstance.defaults.baseURL = BASE_AV_APP_URL;
|
||||
|
||||
// TODO:: Ideally should happen through middlewares.
|
||||
// export const registerNavigateAndDispatch = (
|
||||
// navigateParam: NavigateFunction,
|
||||
// dispatchParam: Dispatch<any>
|
||||
// ) => ((navigate = navigateParam), (dispatch = dispatchParam));
|
||||
export const registerNavigateAndDispatch = (
|
||||
dispatchParam: Dispatch<any>
|
||||
) => ((dispatch = dispatchParam));
|
||||
|
||||
export default axiosInstance;
|
||||
|
||||
Reference in New Issue
Block a user