Start the Next.js frontend: Google login, profile, birth data, admin

services/frontend (Next.js 16, App Router) runs on port 3001 in compose. The
browser only talks to the frontend: /api/v1/* is proxied to the backend, so
the session cookie lives on the frontend's host, and /api/geo/* exposes the
country list and place search of the horoscope-api.

- /belepes: Google Identity Services button, client id from /v1/config
- /profil: account facts, display name and language, own birth data with
  place search, DST ambiguity prompt and the chart's positions
- /admin: user search, role toggles, credit grants (admins only, 404 otherwise)

Services now tolerate migrations newer than their binary, so they can be
rebuilt one at a time.

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-15 21:00:50 +00:00
co-authored by Claude Opus 5.5
parent 4aabb7343c
commit 1f177f859e
38 changed files with 2996 additions and 5 deletions
@@ -0,0 +1,63 @@
"use client";
import Script from "next/script";
import { useRouter } from "next/navigation";
import { useCallback, useEffect, useRef, useState } from "react";
import { api, errorText } from "@/lib/api";
export function GoogleLogin({ clientId, target }: { clientId: string; target: string }) {
const router = useRouter();
const slot = useRef<HTMLDivElement>(null);
const [ready, setReady] = useState(false);
const [error, setError] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
const onCredential = useCallback(
async (response: GoogleCredentialResponse) => {
setBusy(true);
setError(null);
try {
await api("/auth/google", { body: { id_token: response.credential } });
router.replace(target);
router.refresh();
} catch (e) {
setError(errorText(e));
setBusy(false);
}
},
[router, target],
);
useEffect(() => {
const google = window.google;
if (!ready || !google || !slot.current) return;
google.accounts.id.initialize({ client_id: clientId, callback: onCredential, ux_mode: "popup", itp_support: true });
google.accounts.id.renderButton(slot.current, {
theme: "filled_black",
size: "large",
text: "continue_with",
shape: "rectangular",
locale: "hu",
width: Math.min(400, slot.current.clientWidth || 400),
});
}, [ready, clientId, onCredential]);
return (
<div className="field">
<Script
src="https://accounts.google.com/gsi/client"
strategy="afterInteractive"
onReady={() => setReady(true)}
onError={() => setError("Nem sikerült betölteni a Google-belépést. Ellenőrizd a hálózatot vagy a reklámblokkolót.")}
/>
<div ref={slot} className="gsi-slot" aria-busy={busy} />
{busy && <p className="msg muted">Belépés…</p>}
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
</div>
);
}
@@ -0,0 +1,71 @@
import type { Metadata } from "next";
import { redirect } from "next/navigation";
import { Logo } from "@/components/SiteHeader";
import { ZodiacWheel } from "@/components/ZodiacWheel";
import { BACKEND_URL, getMe } from "@/lib/server";
import type { PublicConfig } from "@/lib/types";
import { GoogleLogin } from "./GoogleLogin";
export const metadata: Metadata = { title: "Belépés" };
/** Only local paths, so the login cannot redirect to another site. */
function safeTarget(value: string | string[] | undefined): string {
const v = Array.isArray(value) ? value[0] : value;
return v && v.startsWith("/") && !v.startsWith("//") ? v : "/profil";
}
async function loadConfig(): Promise<PublicConfig | null> {
try {
const res = await fetch(`${BACKEND_URL}/v1/config`, { cache: "no-store" });
return res.ok ? ((await res.json()) as PublicConfig) : null;
} catch {
return null;
}
}
export default async function LoginPage({ searchParams }: { searchParams: Promise<Record<string, string | string[]>> }) {
const target = safeTarget((await searchParams).vissza);
if (await getMe()) redirect(target);
const config = await loadConfig();
const clientId = config?.google_login.enabled ? config.google_login.client_id : null;
return (
<div className="auth">
<aside className="auth-aside">
<Logo />
<ZodiacWheel className="wheel" />
<div className="row" style={{ flexDirection: "column", alignItems: "flex-start", gap: 10, maxWidth: 460 }}>
<p className="tagline">Ahol a csillagok összekötnek.</p>
<p className="muted" style={{ fontSize: 16 }}>
Születési képlet, szinasztria és közösség – egy helyen.
</p>
</div>
</aside>
<main className="auth-main">
<div className="auth-box">
<div className="page-head">
<h1 style={{ fontSize: 44 }}>Belépés</h1>
<p className="muted">Lépj be a Google-fiókoddal. Ha még nincs fiókod, az első belépéskor létrejön.</p>
</div>
{config === null ? (
<p className="msg msg-error" role="alert">
A szerver most nem érhető el. Próbáld újra egy kicsit később.
</p>
) : clientId ? (
<GoogleLogin clientId={clientId} target={target} />
) : (
<p className="msg msg-error" role="alert">
A Google-belépés még nincs beállítva (a backend <code>GOOGLE_CLIENT_IDS</code> változója üres).
</p>
)}
<p className="hint">
A belépéssel elfogadod, hogy a születési adataidat a képleted kiszámításához tároljuk. Bármikor törölheted
őket a profilodban.
</p>
</div>
</main>
</div>
);
}