瀏覽代碼

Update JWT timeout

master
cyril.tsui 1 年之前
父節點
當前提交
35cda75c96
共有 2 個檔案被更改,包括 25 行新增7 行删除
  1. +24
    -7
      src/auth/index.js
  2. +1
    -0
      src/pages/authentication/auth-forms/AuthLoginCustom.js

+ 24
- 7
src/auth/index.js 查看文件

@@ -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)
}
},
)
}

+ 1
- 0
src/pages/authentication/auth-forms/AuthLoginCustom.js 查看文件

@@ -86,6 +86,7 @@ const AuthLoginCustom = () => {
// setSuccess(true)
dispatch(handleLogin(data))
navigate('/dashboard');
location.reload()
// setSumitting(false)
})
.catch((error) => {


Loading…
取消
儲存