Skip to content

Commit

Permalink
Merge pull request #946 from DeepBlueCLtd/inactive_user_token_expire
Browse files Browse the repository at this point in the history
947 inactiver user token expire after 1 hour
  • Loading branch information
IanMayo authored Jan 18, 2024
2 parents edadd34 + 03388d1 commit b51aaa3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"react": "^18.2.0",
"react-admin": "4.13.1",
"react-dom": "^18.2.0",
"react-idle-timer": "^5.7.2",
"react-router-dom": "^6.9.0",
"soul-cli": "^0.6.1",
"vite": "^4.2.0",
Expand Down
13 changes: 13 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { type AxiosError, isAxiosError } from 'axios'
import ChangePassword from './ChangePassword'
import { emitter } from './components/Layout/index'
import { CHANGE_PASSWORD_EVENT } from './constants'
import { useIdleTimer } from 'react-idle-timer'

const style = {
backgroundColor: 'white',
Expand Down Expand Up @@ -115,6 +116,18 @@ function App(): React.ReactElement {
})
const [openChangePasswordModal, setOpenChangePasswordModal] = useState(false)

const handleOnIdle = (): void => {
removeUserToken()
}
const handleOnAction = (): void => {
reset()
}
const { reset } = useIdleTimer({
timeout: 1000 * 60 * 60,
onIdle: handleOnIdle,
onActive: handleOnAction
})

const {
register,
handleSubmit,
Expand Down
8 changes: 2 additions & 6 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const MUTATION_MODE = 'optimistic'
// session storage value.
export const SESSION_LOGIN = 'login'


// major table/resource names
export const R_USERS = 'user'
export const R_BATCHES = 'batch'
Expand Down Expand Up @@ -110,8 +109,6 @@ export const ITEM_SAVE = 'item_save'

export const CHANGE_PASSWORD_EVENT = 'change_password'



export const cosmeticLabels = {
[R_USERS]: 'User',
[R_ITEMS]: 'Item',
Expand All @@ -127,6 +124,5 @@ export const cosmeticLabels = {
[R_CAT_CODE]: 'Cat Code',
[R_CAT_HANDLE]: 'Cat Handle',
[R_DEPARTMENT]: 'Department',
[R_PROTECTIVE_MARKING]: 'Protective Marking',

}
[R_PROTECTIVE_MARKING]: 'Protective Marking'
}
2 changes: 1 addition & 1 deletion src/providers/authProvider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const getCookie = (name: string): string | null => {

const setToken = (token: string): void => {
const date = new Date()
date.setTime(date.getTime() + 1 * 60 * 60 * 1000)
date.setTime(date.getTime() + 24 * 60 * 60 * 1000)
const expires = date.toUTCString()
document.cookie = `${constants.TOKEN_KEY}=${token}; expires=${expires}; path=/ `
}
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6705,6 +6705,11 @@ react-hook-form@^7.43.9:
resolved "https://registry.yarnpkg.com/react-hook-form/-/react-hook-form-7.45.4.tgz#73d228b704026ae95d7e5f7b207a681b173ec62a"
integrity sha512-HGDV1JOOBPZj10LB3+OZgfDBTn+IeEsNOKiq/cxbQAIbKaiJUe/KV8DBUzsx0Gx/7IG/orWqRRm736JwOfUSWQ==

react-idle-timer@^5.7.2:
version "5.7.2"
resolved "https://registry.yarnpkg.com/react-idle-timer/-/react-idle-timer-5.7.2.tgz#f506db28a86645dd1b87987116501703e512142b"
integrity sha512-+BaPfc7XEUU5JFkwZCx6fO1bLVK+RBlFH+iY4X34urvIzZiZINP6v2orePx3E6pAztJGE7t4DzvL7if2SL/0GQ==

react-is@^16.13.1, react-is@^16.7.0:
version "16.13.1"
resolved "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz"
Expand Down

0 comments on commit b51aaa3

Please sign in to comment.