feat(header): identità utente SSR, link Accedi / menu utente
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user