Update
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { formatError } from '../lib/formatError'
|
||||
import { formatAuthError } from '../lib/authError'
|
||||
import { getAuthSession, logout, type AuthSession } from '../services/api/auth'
|
||||
|
||||
const signedOutSession: AuthSession = {
|
||||
@@ -7,6 +7,9 @@ const signedOutSession: AuthSession = {
|
||||
authenticated: false,
|
||||
username: null,
|
||||
expires_at: null,
|
||||
role: null,
|
||||
guest_access_enabled: false,
|
||||
guest_project_id: null,
|
||||
}
|
||||
|
||||
export function useOperatorSession() {
|
||||
@@ -26,7 +29,7 @@ export function useOperatorSession() {
|
||||
.catch((error) => {
|
||||
if (active) {
|
||||
setSession(signedOutSession)
|
||||
setSessionError(formatError(error, 'De aanmeldservice is tijdelijk niet bereikbaar.'))
|
||||
setSessionError(formatAuthError(error, 'De aanmeldservice is tijdelijk niet bereikbaar. Probeer het over enkele ogenblikken opnieuw.'))
|
||||
}
|
||||
})
|
||||
return () => {
|
||||
@@ -36,7 +39,10 @@ export function useOperatorSession() {
|
||||
|
||||
useEffect(() => {
|
||||
const expireSession = () => {
|
||||
setSession(signedOutSession)
|
||||
setSession((current) => ({
|
||||
...signedOutSession,
|
||||
guest_access_enabled: current?.guest_access_enabled ?? false,
|
||||
}))
|
||||
setSessionError('Uw sessie is verlopen. Meld u opnieuw aan.')
|
||||
}
|
||||
window.addEventListener('geointel:session-expired', expireSession)
|
||||
@@ -49,7 +55,7 @@ export function useOperatorSession() {
|
||||
setSession(await logout())
|
||||
setSessionError(null)
|
||||
} catch (error) {
|
||||
setSessionError(formatError(error, 'Uitloggen is niet gelukt.'))
|
||||
setSessionError(formatAuthError(error, 'Uitloggen is niet gelukt. Vernieuw de pagina en probeer opnieuw.'))
|
||||
} finally {
|
||||
setLoggingOut(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user