No browser storage for referrals; the birth chart opens at the drawn chart
CI / test (push) Successful in 1m41s
CI / build (push) Successful in 5m22s
CI / deploy (push) Skipped

The share page stores nothing in the browser any more: the shared link
that brought a visitor travels in its login link (/belepes?ref=...) to
the Google, Apple and password sign-up. The backend counts the same
visitor of a link once in half an hour, instead of a sessionStorage flag.

The public birth chart scrolls to the drawn chart after a calculation
and when coming back to the page. Tabs scrolled to themselves on every
re-render of their parent when the address had a tab (#bolygok); they
now react only to the tab ids and hash changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-21 21:13:41 +00:00
co-authored by Claude Opus 5.5
parent b41dc31f3e
commit 8b8285b5d2
12 changed files with 60 additions and 61 deletions
@@ -55,10 +55,13 @@ export function AppleLogin({
clientId,
target,
inviteToken = null,
referral = null,
}: {
clientId: string;
target: string;
inviteToken?: string | null;
/** The shared link the visitor came from (in the login link: `?ref=`), for the sharer's reward. */
referral?: string | null;
}) {
const router = useRouter();
const [ready, setReady] = useState(false);
@@ -95,20 +98,9 @@ export function AppleLogin({
setBusy(true);
const name = [response.user?.name?.lastName, response.user?.name?.firstName].filter(Boolean).join(" ") || null;
try {
let referral: string | null = null;
try {
referral = localStorage.getItem("sf_ref");
} catch {
// storage blocked
}
await api("/auth/apple", {
body: { id_token: response.authorization.id_token, name, invite_token: inviteToken, referral },
});
try {
localStorage.removeItem("sf_ref");
} catch {
// storage blocked
}
router.replace(target);
router.refresh();
} catch (e) {
@@ -52,11 +52,14 @@ export function GoogleLogin({
clientId,
target,
inviteToken = null,
referral = null,
}: {
clientId: string;
target: string;
/** From an invitation link: lets in any Google account. */
inviteToken?: string | null;
/** The shared link the visitor came from (in the login link: `?ref=`), for the sharer's reward. */
referral?: string | null;
}) {
const router = useRouter();
const slot = useRef<HTMLDivElement>(null);
@@ -72,18 +75,7 @@ export function GoogleLogin({
setError(null);
setUninvited(null);
try {
let referral: string | null = null;
try {
referral = localStorage.getItem("sf_ref");
} catch {
// storage blocked
}
await api("/auth/google", { body: { id_token: response.credential, invite_token: inviteToken, referral } });
try {
localStorage.removeItem("sf_ref");
} catch {
// storage blocked
}
router.replace(target);
router.refresh();
} catch (e) {
@@ -92,7 +84,7 @@ export function GoogleLogin({
setBusy(false);
}
},
[router, target, inviteToken],
[router, target, inviteToken, referral],
);
useEffect(() => {
@@ -24,10 +24,13 @@ function loginError(e: unknown): string {
export function PasswordLogin({
target,
inviteToken = null,
referral = null,
initialMode = "login",
}: {
target: string;
inviteToken?: string | null;
/** The shared link the visitor came from (in the login link: `?ref=`), for the sharer's reward. */
referral?: string | null;
initialMode?: Mode;
}) {
const router = useRouter();
@@ -60,12 +63,6 @@ export function PasswordLogin({
return;
}
if (mode === "register") {
let referral: string | null = null;
try {
referral = localStorage.getItem("sf_ref");
} catch {
// storage blocked
}
await api("/auth/register", {
body: { email, display_name: name.trim() || null, locale: "hu", invite_token: inviteToken, referral },
});
+10 -3
View File
@@ -101,6 +101,9 @@ export default async function LoginPage({ searchParams }: { searchParams: Promis
const clientId = config?.google_login.enabled ? config.google_login.client_id : null;
const appleId = config?.apple_login?.enabled ? config.apple_login.client_id : null;
const pendingInvite = invitation?.status === "pending" ? inviteToken : null;
// The shared link that brought the visitor (from its login button), for the sharer's reward.
const rawRef = Array.isArray(params.ref) ? params.ref[0] : params.ref;
const referral = rawRef && /^[A-Za-z0-9_-]{4,64}$/.test(rawRef) ? rawRef : null;
const inviteOnly = config?.signup_mode === "invite";
const password = config?.password_login === true;
const mod = Array.isArray(params.mod) ? params.mod[0] : params.mod;
@@ -139,8 +142,10 @@ export default async function LoginPage({ searchParams }: { searchParams: Promis
<>
{clientId && (
<div className="field" style={{ gap: 12 }}>
<GoogleLogin clientId={clientId} target={target} inviteToken={pendingInvite} />
{appleId && <AppleLogin clientId={appleId} target={target} inviteToken={pendingInvite} />}
<GoogleLogin clientId={clientId} target={target} inviteToken={pendingInvite} referral={referral} />
{appleId && (
<AppleLogin clientId={appleId} target={target} inviteToken={pendingInvite} referral={referral} />
)}
</div>
)}
{clientId && password && (
@@ -148,7 +153,9 @@ export default async function LoginPage({ searchParams }: { searchParams: Promis
<span>vagy</span>
</div>
)}
{password && <PasswordLogin target={target} inviteToken={pendingInvite} initialMode={initialMode} />}
{password && (
<PasswordLogin target={target} inviteToken={pendingInvite} referral={referral} initialMode={initialMode} />
)}
</>
) : (
<p className="msg msg-error" role="alert">
+1 -1
View File
@@ -1144,7 +1144,7 @@ span.tarot-fan-card { cursor: default; }
/* Public sign calculator (/aszcendens-kalkulator) */
.calc-form { margin-bottom: 8px; }
.calc-result { display: flex; flex-direction: column; gap: 16px; margin: 24px 0 8px; scroll-margin-top: 16px; }
.calc-result { display: flex; flex-direction: column; gap: 16px; margin: 24px 0 8px; scroll-margin-top: 84px; }
.calc-signs { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 16px; }
.calc-sign { display: flex; flex-direction: column; gap: 10px; }
.calc-sign-main { display: flex; align-items: baseline; gap: 10px; }
+1 -1
View File
@@ -92,7 +92,7 @@ export default async function SharedChartPage({ params }: Props) {
<p className="muted">
Add meg a születési adataidat, és megkapod a saját képletedet a rövid összefoglalóval együtt, ingyen.
</p>
<Link href={me ? "/keplet" : "/belepes"} className="btn btn-primary">
<Link href={me ? "/keplet" : `/belepes?ref=${encodeURIComponent(slug)}`} className="btn btn-primary">
{me ? "A saját képletem" : "Elkészítem a sajátomat"}
</Link>
</section>
@@ -172,6 +172,8 @@ export function PublicChart() {
const [error, setError] = useState<string | null>(null);
const [result, setResult] = useState<Saved | null>(null);
const [stored, setStored] = useState(false);
/** After a calculation (smooth) or on coming back (at once): show the drawn chart. */
const [reveal, setReveal] = useState<ScrollBehavior | null>(null);
const minuteRef = useRef<HTMLInputElement>(null);
const resultRef = useRef<HTMLDivElement>(null);
const today = useMemo(() => new Date().toISOString().slice(0, 10), []);
@@ -206,9 +208,19 @@ export function PublicChart() {
if (saved?.result?.chart && saved.birth?.date) {
setResult(saved);
setStored(true);
setReveal("instant");
}
}, []);
// Scrolls to the drawn chart, once it is on the page. An old tab in the
// address (#bolygok) would pull the page down to the tables instead.
useEffect(() => {
if (!reveal || !result) return;
if (window.location.hash) history.replaceState(null, "", window.location.pathname + window.location.search);
resultRef.current?.scrollIntoView({ behavior: reveal, block: "start" });
setReveal(null);
}, [reveal, result]);
/** Forgets the birth data and the chart in this browser. */
function clear() {
try {
@@ -262,12 +274,7 @@ export function PublicChart() {
} catch {
// storage blocked or full: the chart is still shown
}
requestAnimationFrame(() =>
resultRef.current?.scrollIntoView({
behavior: "smooth",
block: "start",
}),
);
setReveal("smooth");
} catch (err) {
if (err instanceof ApiError && err.code === "ambiguous_local_time") {
setAmbiguous(true);