refactor: integrate auth state and action buttons in Header
- Use useAuth composable in Header to query user profile details and handle logout action - Conditionally render User Profile or login/logout action buttons based on auth state - Update design elements to use BIIcon component - Fix minor typo in brand tagline text
This commit is contained in:
+36
-17
@@ -1,10 +1,9 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { ref, computed, watch } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import BIIcon from "~/components/BIIcon.vue";
|
import BIIcon from "~/components/BIIcon.vue";
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
const isMobileMenuOpen = ref(false)
|
const isMobileMenuOpen = ref(false)
|
||||||
|
|
||||||
watch(() => route.path, () => {
|
watch(() => route.path, () => {
|
||||||
@@ -18,7 +17,7 @@ const navLinks = [
|
|||||||
{ name: 'Come funziona', path: '/info' }
|
{ name: 'Come funziona', path: '/info' }
|
||||||
]
|
]
|
||||||
|
|
||||||
const isAuthenticated = ref(false) // Replace with: const token = useCookie('auth_token'); computed(() => !!token.value)
|
const { isAuthenticated, user, logout } = useAuth()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -29,36 +28,56 @@ const isAuthenticated = ref(false) // Replace with: const token = useCookie('aut
|
|||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="it-header-slim-wrapper-content">
|
<div class="it-header-slim-wrapper-content">
|
||||||
<a class="d-none d-lg-block navbar-brand"
|
<a class="d-none d-lg-block navbar-brand"
|
||||||
href="https://www.interno.gov.it/it/ministero/dipartimenti/dipartimento-pubblica-sicurezza">Dipartimento
|
href="https://www.interno.gov.it/it/ministero/dipartimenti/dipartimento-pubblica-sicurezza">
|
||||||
della Pubblica Sicurezza</a>
|
Dipartimento della Pubblica Sicurezza
|
||||||
|
</a>
|
||||||
<div class="nav-mobile">
|
<div class="nav-mobile">
|
||||||
<nav aria-label="Navigazione secondaria">
|
<nav aria-label="Navigazione secondaria">
|
||||||
<a class="it-opener d-lg-none" data-bs-toggle="collapse"
|
<a class="it-opener d-lg-none" data-bs-toggle="collapse"
|
||||||
href="https://www.interno.gov.it/it/ministero/dipartimenti/dipartimento-pubblica-sicurezza"
|
href="https://www.interno.gov.it/it/ministero/dipartimenti/dipartimento-pubblica-sicurezza"
|
||||||
role="button" aria-expanded="false">
|
role="button" aria-expanded="false">
|
||||||
<span>Dipartmento della Pubblica Sicureazza</span>
|
<span>Dipartimento della Pubblica Sicurezza</span>
|
||||||
<BIIcon name="it-expand"/>
|
<BIIcon name="it-expand"/>
|
||||||
</a>
|
</a>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="header-slim-right-zone" role="navigation">
|
<div class="header-slim-right-zone" role="navigation">
|
||||||
<a class="btn btn-primary btn-icon btn-full" href="/auth/login"
|
<!-- Utente Autenticato: Bottone Utente + Bottone Esci -->
|
||||||
data-element="personal-area-login" data-focus-mouse="false">
|
<div v-if="isAuthenticated" class="d-flex align-items-center gap-2">
|
||||||
|
<NuxtLink class="btn btn-primary btn-icon btn-full" to="/dashboard"
|
||||||
|
data-element="personal-area-dashboard" data-focus-mouse="false">
|
||||||
|
<span class="rounded-icon" aria-hidden="true">
|
||||||
|
<BIIcon name="it-user" />
|
||||||
|
</span>
|
||||||
|
<span class="d-none d-lg-block">{{ user?.first_name }}</span>
|
||||||
|
</NuxtLink>
|
||||||
|
|
||||||
|
<button class="btn btn-primary btn-icon btn-full border-0" @click="logout"
|
||||||
|
data-element="personal-area-logout" data-focus-mouse="false">
|
||||||
|
<span class="rounded-icon" aria-hidden="true">
|
||||||
|
<BIIcon name="it-logout" /> <!-- usa it-unlocked se it-logout non è presente -->
|
||||||
|
</span>
|
||||||
|
<span class="d-none d-lg-block">Esci</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Utente NON Autenticato: Bottone Login -->
|
||||||
|
<NuxtLink v-else class="btn btn-primary btn-icon btn-full" to="/auth/login"
|
||||||
|
data-element="personal-area-login" data-focus-mouse="false">
|
||||||
<span class="rounded-icon" aria-hidden="true">
|
<span class="rounded-icon" aria-hidden="true">
|
||||||
<svg class="custom-rounded-icon icon-primary">
|
<BIIcon name="it-user" />
|
||||||
<use
|
|
||||||
xlink:href="https://www.cartaidentita.interno.gov.it/./wp-content/themes/design-italia/lib/bootstrap-italia/svg/sprite.svg#it-user"></use>
|
|
||||||
</svg>
|
|
||||||
</span>
|
</span>
|
||||||
<span class="d-none d-lg-block">Login</span>
|
<span class="d-none d-lg-block">Login</span>
|
||||||
</a></div>
|
</NuxtLink>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- CENTER HEADER (Brand) -->
|
|
||||||
<div class="it-nav-wrapper">
|
<div class="it-nav-wrapper">
|
||||||
<div class="it-header-center-wrapper">
|
<div class="it-header-center-wrapper">
|
||||||
<div class="container-xxl">
|
<div class="container-xxl">
|
||||||
@@ -70,7 +89,7 @@ const isAuthenticated = ref(false) // Replace with: const token = useCookie('aut
|
|||||||
<BIIcon name="it-pa"/>
|
<BIIcon name="it-pa"/>
|
||||||
<div class="it-brand-text">
|
<div class="it-brand-text">
|
||||||
<div class="it-brand-title">Visione</div>
|
<div class="it-brand-title">Visione</div>
|
||||||
<div class="it-brand-tagline d-none d-md-block">Un'occhio per la sicurezza del cittadino.</div>
|
<div class="it-brand-tagline d-none d-md-block">Un occhio per la sicurezza del cittadino.</div>
|
||||||
</div>
|
</div>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
@@ -153,8 +172,8 @@ const isAuthenticated = ref(false) // Replace with: const token = useCookie('aut
|
|||||||
background-color: rgb(0, 76.5, 153);
|
background-color: rgb(0, 76.5, 153);
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.it-header-slim-wrapper .it-header-slim-wrapper-content .header-slim-right-zone a) {
|
:deep(.it-header-slim-wrapper .it-header-slim-wrapper-content .header-slim-right-zone a),
|
||||||
|
:deep(.it-header-slim-wrapper .it-header-slim-wrapper-content .header-slim-right-zone button) {
|
||||||
background-color: rgb(0, 76.5, 153);
|
background-color: rgb(0, 76.5, 153);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user