2026-05-21 23:41:19 +02:00
|
|
|
'use client';
|
|
|
|
|
|
2026-05-27 12:20:25 +02:00
|
|
|
import { PulseLink } from '@/components/pulse';
|
2026-05-21 23:41:19 +02:00
|
|
|
import { apiFetch } from '@/lib/api';
|
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
|
|
|
|
|
/**
|
2026-05-25 19:30:27 +02:00
|
|
|
* Marketing-header CTA that reflects the session: logged-out visitors see a
|
|
|
|
|
* "Login" button, signed-in users see "Dashboard". Same button slot so the
|
|
|
|
|
* header layout doesn't shift between states.
|
|
|
|
|
*
|
|
|
|
|
* While the auth probe is in flight (`authed === null`) we default to the
|
|
|
|
|
* logged-out label — most marketing-page visitors are anonymous, so this
|
|
|
|
|
* avoids a "Dashboard → Login" flicker for them. Authed users see a single
|
|
|
|
|
* "Login → Dashboard" swap once the /v1/auth/me round-trip completes.
|
2026-05-21 23:41:19 +02:00
|
|
|
*/
|
|
|
|
|
export function MarketingAuthButtons() {
|
|
|
|
|
const [authed, setAuthed] = useState<boolean | null>(null);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
apiFetch('/v1/auth/me')
|
|
|
|
|
.then(() => setAuthed(true))
|
|
|
|
|
.catch(() => setAuthed(false));
|
|
|
|
|
}, []);
|
|
|
|
|
|
2026-05-25 19:30:27 +02:00
|
|
|
const showDashboard = authed === true;
|
2026-05-21 23:41:19 +02:00
|
|
|
|
|
|
|
|
return (
|
2026-05-27 12:20:25 +02:00
|
|
|
<PulseLink
|
2026-05-25 19:30:27 +02:00
|
|
|
href={showDashboard ? '/dashboard' : '/login'}
|
|
|
|
|
className="rounded-md bg-[--color-accent] px-3 py-1.5 text-[13px] font-medium text-white transition-colors duration-200 hover:bg-[#5557e8]"
|
|
|
|
|
>
|
|
|
|
|
{showDashboard ? 'Dashboard' : 'Login'}
|
2026-05-27 12:20:25 +02:00
|
|
|
</PulseLink>
|
2026-05-21 23:41:19 +02:00
|
|
|
);
|
|
|
|
|
}
|