Skip to content

Commit

Permalink
Merge branch 'release-0.2.0' into fix/hamed-unauthorized-page-setup-1616
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-valiollahi authored Jan 16, 2025
2 parents 9696832 + 7ffaa75 commit a3123e1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
12 changes: 10 additions & 2 deletions frontend/src/components/KeycloakProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import React, { useEffect } from 'react'
import { ReactKeycloakProvider } from '@react-keycloak/web'
import Loading from '@/components/Loading'
import { keycloakInitOptions } from '@/utils/keycloak'
import { keycloakInitOptions, refreshToken } from '@/utils/keycloak'
import { apiRoutes } from '@/constants/routes'
import axios from 'axios'
import { CONFIG } from '@/constants/config'
Expand All @@ -20,6 +20,14 @@ export const KeycloakProvider = ({ authClient, children }) => {
)
}

useEffect(() => {
window.addEventListener('click', refreshToken)

return () => {
window.removeEventListener('click', refreshToken)
}
}, [])

const handleOnEvent = async (event) => {
if (event === 'onAuthSuccess') {
const hasBeenTracked =
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/utils/keycloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,17 @@ export const logout = () => {

window.location = url
}

export const refreshToken = () => {
keycloak
.updateToken(60) // Minimum validity in seconds
.then((refreshed) => {
if (refreshed) {
console.log('Token refreshed')
}
})
.catch(() => {
console.error('Failed to refresh token')
logout()
})
}
2 changes: 1 addition & 1 deletion frontend/src/views/Admin/AdminMenu/components/AuditLog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const AuditLog = () => {
}

const getRowId = useCallback((params) => {
return params.data.auditLogId
return params.data.auditLogId.toString()
}, [])

const apiEndpoint = apiRoutes.getAuditLogs
Expand Down

0 comments on commit a3123e1

Please sign in to comment.