feat: add error handling for CIE authentication and display messages on login page
This commit is contained in:
@@ -35,10 +35,23 @@ const scheduleNextPoll = () => {
|
|||||||
pollTimer = setTimeout(checkSession, 2000)
|
pollTimer = setTimeout(checkSession, 2000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const redirectToLoginError = async (code: string, fallbackMessage: string) => {
|
||||||
|
stopPolling()
|
||||||
|
isLoading.value = false
|
||||||
|
|
||||||
|
try {
|
||||||
|
await router.replace({
|
||||||
|
path: '/auth/login',
|
||||||
|
query: { cie_error: code }
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
errorMessage.value = fallbackMessage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const checkSession = async () => {
|
const checkSession = async () => {
|
||||||
if (!state.value) {
|
if (!state.value) {
|
||||||
isLoading.value = false
|
await redirectToLoginError('invalid_session', 'Sessione CIE non valida: parametro state mancante.')
|
||||||
errorMessage.value = 'Sessione CIE non valida: parametro state mancante.'
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,25 +67,19 @@ const checkSession = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (['failed', 'expired', 'cancelled', 'error'].includes(res.status)) {
|
if (['failed', 'expired', 'cancelled', 'error'].includes(res.status)) {
|
||||||
stopPolling()
|
await redirectToLoginError('failed', 'Autenticazione CIE non completata. Riprova dal login.')
|
||||||
isLoading.value = false
|
|
||||||
errorMessage.value = 'Autenticazione CIE non completata. Riprova dal login.'
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attempts >= maxAttempts) {
|
if (attempts >= maxAttempts) {
|
||||||
stopPolling()
|
await redirectToLoginError('timeout', 'Tempo di attesa scaduto durante la verifica CIE. Riprova.')
|
||||||
isLoading.value = false
|
|
||||||
errorMessage.value = 'Tempo di attesa scaduto durante la verifica CIE. Riprova.'
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
statusMessage.value = 'Autenticazione completata sul provider. Attendo conferma finale da Visione...'
|
statusMessage.value = 'Autenticazione completata sul provider. Attendo conferma finale da Visione...'
|
||||||
scheduleNextPoll()
|
scheduleNextPoll()
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
stopPolling()
|
await redirectToLoginError('verification_error', err.data?.message || 'Errore durante la verifica della sessione CIE.')
|
||||||
isLoading.value = false
|
|
||||||
errorMessage.value = err.data?.message || 'Errore durante la verifica della sessione CIE.'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ definePageMeta({
|
|||||||
useHead({ title: 'Accedi - Visione' })
|
useHead({ title: 'Accedi - Visione' })
|
||||||
|
|
||||||
const runtimeConfig = useRuntimeConfig()
|
const runtimeConfig = useRuntimeConfig()
|
||||||
|
const route = useRoute()
|
||||||
const { requestOtp, verifyOtp, handleLoginSuccess, startCieLogin } = useAuth()
|
const { requestOtp, verifyOtp, handleLoginSuccess, startCieLogin } = useAuth()
|
||||||
|
|
||||||
const otpStep = ref<1 | 2>(1)
|
const otpStep = ref<1 | 2>(1)
|
||||||
@@ -20,6 +21,21 @@ const otpCode = ref('')
|
|||||||
|
|
||||||
const cieCallbackUrl = `${runtimeConfig.public.url}/auth/cie/callback`
|
const cieCallbackUrl = `${runtimeConfig.public.url}/auth/cie/callback`
|
||||||
|
|
||||||
|
const cieErrorMessage = computed(() => {
|
||||||
|
const error = route.query.cie_error
|
||||||
|
|
||||||
|
if (typeof error !== 'string') return ''
|
||||||
|
|
||||||
|
const messages: Record<string, string> = {
|
||||||
|
invalid_session: 'Sessione CIE non valida o incompleta. Avvia di nuovo accesso con CIE.',
|
||||||
|
failed: 'Autenticazione CIE non completata. Riprova dal pulsante Entra con CIE.',
|
||||||
|
timeout: 'Tempo di attesa scaduto durante verifica CIE. Riprova.',
|
||||||
|
verification_error: 'Errore durante verifica autenticazione CIE. Riprova tra poco.'
|
||||||
|
}
|
||||||
|
|
||||||
|
return messages[error] || 'Accesso con CIE non riuscito. Riprova.'
|
||||||
|
})
|
||||||
|
|
||||||
const handleRequestOtp = async () => {
|
const handleRequestOtp = async () => {
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
errorMessage.value = ''
|
errorMessage.value = ''
|
||||||
@@ -94,6 +110,10 @@ const handleCieLogin = async () => {
|
|||||||
<hr class="flex-grow-1">
|
<hr class="flex-grow-1">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div v-if="cieErrorMessage" class="alert alert-danger mb-4" role="alert">
|
||||||
|
{{ cieErrorMessage }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-if="errorMessage" class="alert alert-danger mb-4" role="alert">
|
<div v-if="errorMessage" class="alert alert-danger mb-4" role="alert">
|
||||||
{{ errorMessage }}
|
{{ errorMessage }}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user