|
|
@@ -93,6 +93,7 @@ export const handleLogoutFunction = () => { |
|
|
|
localStorage.removeItem(windowCount) |
|
|
|
localStorage.removeItem(predictProductionQty) |
|
|
|
localStorage.removeItem(predictUsageCount) |
|
|
|
setTimeout(()=> localStorage.removeItem("expiredAlertShown"), 5000) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -109,11 +110,14 @@ export const SetupAxiosInterceptors = () => { |
|
|
|
// ** If token is present add it to request's Authorization Header |
|
|
|
if (isUserLoggedIn()) { |
|
|
|
config.headers.Authorization = `${jwtApplicationConfig.tokenType} ${accessToken}` |
|
|
|
config.data = config.data === undefined ? JSON.stringify({refreshToken:null}) : config.data |
|
|
|
} |
|
|
|
config.headers['X-Authorization'] = process.env.REACT_APP_API_KEY |
|
|
|
return config |
|
|
|
}, |
|
|
|
error => Promise.reject(error) |
|
|
|
error => { |
|
|
|
Promise.reject(error) |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
axios.interceptors.response.use( |
|
|
@@ -124,23 +128,36 @@ export const SetupAxiosInterceptors = () => { |
|
|
|
error => { |
|
|
|
// ** const { config, response: { status } } = error |
|
|
|
const {response} = error |
|
|
|
|
|
|
|
if (error.response.status === 401) { |
|
|
|
dispatch(handleLogoutFunction()); |
|
|
|
navigate('/login'); |
|
|
|
if (localStorage.getItem("expiredAlertShown") === null) { |
|
|
|
localStorage.setItem("expiredAlertShown", true) |
|
|
|
alert("登入驗證已過期,請重新登入。") |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ** if (status === 401) { |
|
|
|
if (response.status === 401) { |
|
|
|
dispatch(handleLogoutFunction()); |
|
|
|
navigate('/login'); |
|
|
|
if (localStorage.getItem("expiredAlertShown") === null) { |
|
|
|
localStorage.setItem("expiredAlertShown", true) |
|
|
|
alert("登入驗證已過期,請重新登入。") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (response && response.status === 401) { |
|
|
|
if (localStorage.getItem("expiredAlertShown") === null) { |
|
|
|
localStorage.setItem("expiredAlertShown", true) |
|
|
|
alert("登入驗證已過期,請重新登入。") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (localStorage.getItem("expiredAlertShown")) { |
|
|
|
dispatch(handleLogoutFunction()); |
|
|
|
navigate('/login'); |
|
|
|
} |
|
|
|
|
|
|
|
return Promise.reject(error) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
) |
|
|
|
} |