From 4c42c7963cf9228add845fbf2f5bd31492afe9da Mon Sep 17 00:00:00 2001 From: gabdevele Date: Wed, 17 Jun 2026 18:03:40 +0200 Subject: [PATCH] feat: add CIE authentication callback page with polling mechanism for session verification --- app/composables/useAuth.ts | 13 + app/pages/auth/cie/callback.vue | 119 +++ app/pages/auth/login.vue | 30 +- app/types/api.d.ts | 35 + yarn.lock | 1229 +++++-------------------------- 5 files changed, 397 insertions(+), 1029 deletions(-) create mode 100644 app/pages/auth/cie/callback.vue diff --git a/app/composables/useAuth.ts b/app/composables/useAuth.ts index 30ec5b1..057371b 100644 --- a/app/composables/useAuth.ts +++ b/app/composables/useAuth.ts @@ -1,4 +1,6 @@ import type { + CieSessionResponse, + CieStartResponse, CurrentUserResponse, EmailRequest, NotificationListResponse, OkResponse, OtpRequestResponse, RegisterCitizenRequest, @@ -82,6 +84,15 @@ export const useAuth = () => { const verifyOtp = (body: VerifyOtpRequest) => useApiFetch('/api/v1/auth/otp/verify', { method: 'POST', body }) + const startCieLogin = (frontendRedirectUri: string) => + useApiFetch('/api/v1/auth/cie/start', { + method: 'POST', + body: { frontend_redirect_uri: frontendRedirectUri } + }) + + const fetchCieSession = (id: string) => + useApiFetch(`/api/v1/auth/cie/session/${id}`, { method: 'GET' }) + const updateProfile = (body: UpdateProfileRequest) => useApiFetch('/api/v1/me', { method: 'PATCH', body }) @@ -110,6 +121,8 @@ export const useAuth = () => { register, requestOtp, verifyOtp, + startCieLogin, + fetchCieSession, updateProfile, fetchCurrentUser, fetchRewards, diff --git a/app/pages/auth/cie/callback.vue b/app/pages/auth/cie/callback.vue new file mode 100644 index 0000000..777842e --- /dev/null +++ b/app/pages/auth/cie/callback.vue @@ -0,0 +1,119 @@ + + + diff --git a/app/pages/auth/login.vue b/app/pages/auth/login.vue index 38ccab9..5087beb 100644 --- a/app/pages/auth/login.vue +++ b/app/pages/auth/login.vue @@ -7,16 +7,20 @@ definePageMeta({ useHead({ title: 'Accedi - Visione' }) -const { requestOtp, verifyOtp, handleLoginSuccess } = useAuth() +const runtimeConfig = useRuntimeConfig() +const { requestOtp, verifyOtp, handleLoginSuccess, startCieLogin } = useAuth() // UI State const otpStep = ref<1 | 2>(1) const isLoading = ref(false) +const isCieLoading = ref(false) const errorMessage = ref('') const email = ref('') const otpCode = ref('') +const cieCallbackUrl = `${runtimeConfig.public.url}/auth/cie/callback` + const handleRequestOtp = async () => { isLoading.value = true errorMessage.value = '' @@ -42,6 +46,21 @@ const handleVerifyOtp = async () => { isLoading.value = false } } + +const handleCieLogin = async () => { + isCieLoading.value = true + errorMessage.value = '' + try { + const res = await startCieLogin(cieCallbackUrl) + await navigateTo(res.authorization_url, { + external: true, + replace: true, + }) + } catch (err: any) { + errorMessage.value = err.data?.message || 'Avvio autenticazione CIE non riuscito. Riprova.' + isCieLoading.value = false + } +}