fix(frontend): redirect user to DEFAULT_FALLBACK_URL when permissions update fails after PERMISSIONS_UPDATED message

Fixes #6475

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares
2026-05-13 19:54:22 +02:00
committed by Erik Michelson
parent f9077d7ff5
commit fb87cee9c2
@@ -9,6 +9,11 @@ import type { MessageTransporter } from '@hedgedoc/commons'
import { MessageType } from '@hedgedoc/commons'
import type { Listener } from 'eventemitter2'
import { useEffect } from 'react'
import { Logger } from '../../../../../utils/logger'
import { DEFAULT_FALLBACK_URL } from '../../../../login-page/utils/use-get-post-login-redirect-url'
import { useRouter } from 'next/navigation'
const logger = new Logger('useOnPermissionsUpdated')
/**
* Hook that updates the permissions state in the redux if the server announced an update of the note permissions.
@@ -17,14 +22,18 @@ import { useEffect } from 'react'
*/
export const useOnPermissionsUpdated = (websocketConnection: MessageTransporter): void => {
const { showErrorNotificationBuilder } = useUiNotifications()
const router = useRouter()
useEffect(() => {
const listener = websocketConnection.on(
MessageType.PERMISSIONS_UPDATED,
() => {
updateNotePermissions().catch(
showErrorNotificationBuilder('common.errorWhileLoading', { name: 'note permission update' })
)
updateNotePermissions().catch(() => {
logger.error(
`Got an error while updating note permissions after receiving ${MessageType.PERMISSIONS_UPDATED}. Returning the user to explore page`
)
router.replace(DEFAULT_FALLBACK_URL)
})
},
{
objectify: true
@@ -33,5 +42,5 @@ export const useOnPermissionsUpdated = (websocketConnection: MessageTransporter)
return () => {
listener.off()
}
}, [showErrorNotificationBuilder, websocketConnection])
}, [showErrorNotificationBuilder, websocketConnection, router])
}