Skip to content

Commit b423c0f

Browse files
fix(admin-ui): prevent admin login failure when admin roles are removed (#2689)
1 parent 39f6277 commit b423c0f

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

admin-ui/app/locales/en/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,8 @@
10101010
"auth_error_token_fetch": "Token or user info fetch failed",
10111011
"auth_error_no_code": "Unable to get authorization code",
10121012
"mau_loading": "Loading statistics...",
1013-
"vs_previous_period": "vs previous period"
1013+
"vs_previous_period": "vs previous period",
1014+
"no_valid_role_logout": "The logged-in user does not have a valid role. You will be logged out in {{seconds}} seconds."
10141015
},
10151016
"errors": {
10161017
"attribute_create_failed": "Error creating attribute",

admin-ui/app/locales/es/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,8 @@
10041004
"auth_error_token_fetch": "Error al obtener el token o la información del usuario",
10051005
"auth_error_no_code": "No se pudo obtener el código de autorización",
10061006
"mau_loading": "Cargando estadísticas...",
1007-
"vs_previous_period": "vs período anterior"
1007+
"vs_previous_period": "vs período anterior",
1008+
"no_valid_role_logout": "El usuario no tiene un rol válido. Se cerrará la sesión en {{seconds}} segundos."
10081009
},
10091010
"errors": {
10101011
"attribute_create_failed": "Error al crear el atributo",

admin-ui/app/locales/fr/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,8 @@
950950
"audit_description": "Afficher et rechercher les journaux d'audit du système dans une plage de dates",
951951
"showing_entries": "Affichage de {{start}} à {{end}} sur {{total}} entrées",
952952
"start_date_after_end": "La date de début ne peut pas être postérieure à la date de fin",
953-
"both_dates_required": "Les dates de début et de fin sont requises pour le filtrage par plage de dates"
953+
"both_dates_required": "Les dates de début et de fin sont requises pour le filtrage par plage de dates",
954+
"no_valid_role_logout": "L'utilisateur n'a pas de rôle valide. Déconnexion dans {{seconds}} secondes."
954955
},
955956
"errors": {
956957
"attribute_create_failed": "Erreur lors de la création de l'attribut",

admin-ui/app/locales/pt/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,8 @@
945945
"audit_description": "Visualizar e pesquisar registros de auditoria do sistema dentro de um intervalo de datas",
946946
"showing_entries": "Mostrando {{start}} a {{end}} de {{total}} entradas",
947947
"start_date_after_end": "A data de início não pode ser posterior à data de fim",
948-
"both_dates_required": "As datas de início e fim são obrigatórias para filtragem por intervalo de datas"
948+
"both_dates_required": "As datas de início e fim são obrigatórias para filtragem por intervalo de datas",
949+
"no_valid_role_logout": "O utilizador não possui um papel válido. Sessão será encerrada em {{seconds}} segundos."
949950
},
950951
"errors": {
951952
"attribute_create_failed": "Erro ao criar atributo",

admin-ui/app/utils/AppAuthProvider.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { checkLicenseConfigValid, getUserInfoResponse } from '../redux/actions'
1010
import { getAPIAccessToken, checkLicensePresent } from 'Redux/actions'
1111
import GluuTimeoutModal from 'Routes/Apps/Gluu/GluuTimeoutModal'
1212
import GluuErrorModal from 'Routes/Apps/Gluu/GluuErrorModal'
13+
import GluuToast from 'Routes/Apps/Gluu/GluuToast'
14+
import { toast } from 'react-toastify'
1315
import { updateToast } from 'Redux/features/toastSlice'
1416
import {
1517
FetchRequestor,
@@ -30,6 +32,7 @@ import {
3032
fetchUserInformation,
3133
type FetchUserInfoResult,
3234
} from 'Redux/api/backend-api'
35+
import { useTranslation } from 'react-i18next'
3336
import { jwtDecode } from 'jwt-decode'
3437
import type { UserInfo } from '@/redux/features/types/authTypes'
3538

@@ -50,9 +53,12 @@ interface AppAuthProviderProps {
5053
children: ReactNode
5154
}
5255

56+
const LOGOUT_DELAY_SECONDS = 10
57+
5358
export default function AppAuthProvider({ children }: Readonly<AppAuthProviderProps>) {
5459
const dispatch = useAppDispatch()
5560
const location = useLocation()
61+
const { t } = useTranslation()
5662
const [roleNotFound, setRoleNotFound] = useState(false)
5763
const [showAdminUI, setShowAdminUI] = useState(false)
5864
const {
@@ -236,11 +242,16 @@ export default function AppAuthProvider({ children }: Readonly<AppAuthProviderPr
236242

237243
if (!hasValidRole) {
238244
setShowAdminUI(false)
239-
alert('The logged-in user do not have valid role. Logging out of Admin UI')
240245
setRoleNotFound(true)
241246
const state = uuidv4()
242247
const sessionEndpoint = `${authConfigs?.endSessionEndpoint ?? ''}?state=${state}&post_logout_redirect_uri=${localStorage.getItem('postLogoutRedirectUri') ?? ''}`
243-
window.location.href = sessionEndpoint
248+
const redirect = () => {
249+
window.location.href = sessionEndpoint
250+
}
251+
toast.error(t('messages.no_valid_role_logout', { seconds: LOGOUT_DELAY_SECONDS }), {
252+
autoClose: LOGOUT_DELAY_SECONDS * 1000,
253+
onClose: redirect,
254+
})
244255
return
245256
}
246257

@@ -274,6 +285,7 @@ export default function AppAuthProvider({ children }: Readonly<AppAuthProviderPr
274285

275286
return (
276287
<React.Fragment>
288+
<GluuToast />
277289
<SessionTimeout isAuthenticated={showAdminUI} />
278290
<GluuTimeoutModal
279291
description={

0 commit comments

Comments
 (0)