Files
SIB/frontend/src/components/common/AuthGuard.vue

223 lines
4.7 KiB
Vue

<script setup lang="ts">
import { useAuthStore } from '@/stores/auth'
import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
interface Props {
title?: string
message?: string
actionLabel?: string
showOnGuest?: boolean // If false, the guard won't trigger (standard behavior)
}
const props = withDefaults(defineProps<Props>(), {
title: '¡Desbloquea contenido exclusivo!',
message: 'Regístrate para ver todos los detalles, ofertas y rutas recomendadas.',
actionLabel: 'Unirme ahora',
showOnGuest: true
})
const authStore = useAuthStore()
const router = useRouter()
const { t } = useI18n()
function goToRegister() {
router.push({ path: '/login', query: { mode: 'register' } })
}
function goToLogin() {
router.push('/login')
}
</script>
<template>
<div class="auth-guard-container">
<!-- Slot for the actual content -->
<div
class="content-wrapper"
:class="{ 'content-blurred': !authStore.isAuthenticated && props.showOnGuest }"
>
<slot />
</div>
<!-- Overlay (only visible if not authenticated) -->
<Transition name="fade-scale">
<div
v-if="!authStore.isAuthenticated && props.showOnGuest"
class="auth-overlay"
>
<div class="auth-card glass-effect">
<div class="auth-icon-circle">
<span class="material-icons">lock</span>
</div>
<h3 class="auth-title">{{ props.title }}</h3>
<p class="auth-message">{{ props.message }}</p>
<div class="auth-actions">
<button class="primary-btn" @click="goToRegister">
<span class="material-icons">person_add</span>
{{ props.actionLabel }}
</button>
<button class="secondary-btn" @click="goToLogin">
{{ t('auth.loginTab') || 'Entrar' }}
</button>
</div>
</div>
</div>
</Transition>
</div>
</template>
<style scoped>
.auth-guard-container {
position: relative;
width: 100%;
}
.content-wrapper {
transition: filter 0.5s ease, opacity 0.5s ease;
}
.content-blurred {
filter: blur(14px);
pointer-events: none;
user-select: none;
opacity: 0.7;
}
/* ── OVERLAY ── */
.auth-overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
z-index: 50;
padding: 1rem;
background: rgba(var(--bg-primary-rgb), 0.4);
backdrop-filter: blur(4px);
}
.auth-card {
max-width: 290px;
width: 100%;
padding: 1rem;
border-radius: 1.25rem;
text-align: center;
border: 1px solid rgba(255, 255, 255, 0.1);
box-shadow: 0 15px 35px -5px rgba(0, 0, 0, 0.5);
display: flex;
flex-direction: column;
align-items: center;
gap: 0.5rem;
animation: float 6s ease-in-out infinite;
}
.auth-icon-circle {
width: 32px;
height: 32px;
background: var(--active-color);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 0;
}
.auth-icon-circle .material-icons {
font-size: 1.1rem;
color: #101820;
}
.auth-title {
font-size: 0.95rem;
font-weight: 900;
color: var(--text-primary);
margin: 0;
line-height: 1.1;
}
.auth-message {
font-size: 0.75rem;
color: var(--text-secondary);
line-height: 1.3;
margin: 0;
}
/* ── ACTIONS ── */
.auth-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.4rem;
width: 100%;
margin-top: 0.25rem;
}
.primary-btn {
display: flex;
align-items: center;
justify-content: center;
gap: 0.3rem;
padding: 0.6rem 0.4rem;
background: var(--active-color);
color: #101820;
border: none;
border-radius: 0.6rem;
font-weight: 800;
font-size: 0.75rem;
cursor: pointer;
white-space: nowrap;
transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.primary-btn:hover {
transform: scale(1.03);
box-shadow: 0 10px 20px rgba(254, 231, 21, 0.3);
}
.secondary-btn {
padding: 0.6rem 0.4rem;
background: rgba(255,255,255,0.05);
color: var(--text-primary);
border: 1px solid rgba(255,255,255,0.2);
border-radius: 0.6rem;
font-weight: 700;
font-size: 0.75rem;
cursor: pointer;
white-space: nowrap;
transition: all 0.2s;
}
.secondary-btn:hover {
background: var(--bg-secondary);
border-color: var(--active-color);
}
/* ── ANIMATIONS ── */
.fade-scale-enter-active,
.fade-scale-leave-active {
transition: all 0.4s ease;
}
.fade-scale-enter-from,
.fade-scale-leave-to {
opacity: 0;
transform: scale(0.95) translateY(10px);
}
@keyframes float {
0% { transform: translateY(0px); }
50% { transform: translateY(-10px); }
100% { transform: translateY(0px); }
}
/* Dark mode utility */
:root {
--bg-primary-rgb: 16, 24, 32; /* SIBU Dark primary */
}
</style>