feat(header): identità utente SSR, link Accedi / menu utente

This commit is contained in:
2026-07-05 22:03:07 +02:00
parent 6b85872515
commit 71cd1626e0
2 changed files with 40 additions and 8 deletions
+7 -8
View File
@@ -14,12 +14,11 @@ import { getSessionUser, SESSION_COOKIE } from '../lib/auth';
interface Props { title: string; description?: string }
const { title, description = 'InsanityLab — Performance. Balance. Longevity. Allenamento personalizzato, piccoli gruppi e benessere a Bologna.' } = Astro.props;
// Overlay annotate: badge coi tag contenuto, solo per utenti loggati con ?annotate=1.
let annotate = false;
if (Astro.url.searchParams.get('annotate') === '1') {
const tok = Astro.cookies.get(SESSION_COOKIE)?.value;
annotate = Boolean(tok && getSessionUser(getDb(), tok));
}
const tok = Astro.cookies.get(SESSION_COOKIE)?.value;
const user = tok ? getSessionUser(getDb(), tok) : null;
const canTags = !!user && (user.role === 'superuser' || user.role === 'admin');
const wantTags = Astro.cookies.get('showtags')?.value === '1' || Astro.url.searchParams.get('annotate') === '1';
const showTags = canTags && wantTags;
---
<!doctype html>
<html lang="it">
@@ -37,7 +36,7 @@ if (Astro.url.searchParams.get('annotate') === '1') {
<script is:inline>document.documentElement.classList.add('js');</script>
</head>
<body>
<Header />
<Header user={user} showTags={showTags} canTags={canTags} />
<main><slot /></main>
<Footer />
<script>
@@ -74,7 +73,7 @@ if (Astro.url.searchParams.get('annotate') === '1') {
update();
}
</script>
{annotate && (
{showTags && (
<style is:global>
[data-tag] { outline: 1px dashed #b8a98c; outline-offset: 2px; }
.tag-badge { position: absolute; z-index: 9999; background: #3a2929; color: #fff;