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,182 @@
"use client";
import { useCallback, useEffect, useState } from "react";
import { api, errorText } from "@/lib/api";
import { ROLE_LABELS, formatDate } from "@/lib/astro";
import type { AdminUser, Role } from "@/lib/types";
const EDITABLE_ROLES: Role[] = ["user", "premium", "vip", "creator", "admin"];
export function AdminUsers({ selfId }: { selfId: string }) {
const [query, setQuery] = useState("");
const [users, setUsers] = useState<AdminUser[] | null>(null);
const [error, setError] = useState<string | null>(null);
const load = useCallback(async (q: string) => {
try {
const data = await api<{ users: AdminUser[] }>(`/admin/users?q=${encodeURIComponent(q)}`);
setUsers(data.users);
setError(null);
} catch (e) {
setError(errorText(e));
}
}, []);
useEffect(() => {
const t = setTimeout(() => load(query.trim()), 250);
return () => clearTimeout(t);
}, [query, load]);
return (
<section className="card" aria-label="Felhasználók listája">
<div className="field" style={{ maxWidth: 420 }}>
<label htmlFor="user-search">Keresés név vagy e-mail alapján</label>
<input
id="user-search"
className="inp"
type="search"
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder="pl. anna@"
/>
</div>
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
{users === null ? (
<p className="muted">Betöltés…</p>
) : users.length === 0 ? (
<p className="muted">Nincs találat.</p>
) : (
<div className="table-wrap">
<table>
<thead>
<tr>
<th scope="col">Felhasználó</th>
<th scope="col">Szerepkörök</th>
<th scope="col">Kredit</th>
<th scope="col">Képletek</th>
<th scope="col">Regisztrált</th>
<th scope="col">Utoljára belépett</th>
</tr>
</thead>
<tbody>
{users.map((u) => (
<UserRow
key={u.id}
user={u}
isSelf={u.id === selfId}
onChange={(next) => setUsers((list) => list?.map((x) => (x.id === next.id ? next : x)) ?? null)}
/>
))}
</tbody>
</table>
</div>
)}
</section>
);
}
function UserRow({ user, isSelf, onChange }: { user: AdminUser; isSelf: boolean; onChange: (u: AdminUser) => void }) {
const [status, setStatus] = useState<{ ok: boolean; text: string } | null>(null);
const [busy, setBusy] = useState(false);
const [delta, setDelta] = useState("");
async function toggleRole(role: Role, on: boolean) {
const roles = on ? [...user.roles, role] : user.roles.filter((r) => r !== role);
if (roles.length === 0) return setStatus({ ok: false, text: "Legalább egy szerepkör kell." });
setBusy(true);
setStatus(null);
try {
const res = await api<{ roles: Role[] }>(`/admin/users/${user.id}`, { method: "PATCH", body: { roles } });
onChange({ ...user, roles: res.roles });
} catch (e) {
setStatus({ ok: false, text: errorText(e) });
} finally {
setBusy(false);
}
}
async function grant(e: React.FormEvent) {
e.preventDefault();
const n = Number.parseInt(delta, 10);
if (!Number.isFinite(n) || n === 0) return setStatus({ ok: false, text: "Adj meg egy nem nulla egész számot." });
setBusy(true);
setStatus(null);
try {
await api(`/admin/users/${user.id}/credits`, { body: { delta: n, note: "admin" } });
onChange({ ...user, credits: user.credits + n });
setDelta("");
setStatus({ ok: true, text: n > 0 ? `+${n} kredit` : `${n} kredit` });
} catch (e) {
setStatus({ ok: false, text: errorText(e) });
} finally {
setBusy(false);
}
}
return (
<tr>
<td>
<div>{user.display_name || <span className="muted">(nincs név)</span>}</div>
<div className="muted" style={{ fontSize: 13 }}>
{user.email}
{isSelf && " · te"}
</div>
</td>
<td>
<div className="row" style={{ gap: 4 }}>
{EDITABLE_ROLES.map((role) => {
const on = user.roles.includes(role);
const locked = isSelf && role === "admin";
return (
<label key={role} className="check" style={{ minHeight: 28, fontSize: 13, marginRight: 8 }}>
<input
type="checkbox"
checked={on}
disabled={busy || locked}
onChange={(e) => toggleRole(role, e.target.checked)}
title={locked ? "A saját admin szerepköröd nem veheted el." : undefined}
/>
{ROLE_LABELS[role]}
</label>
);
})}
</div>
</td>
<td>
<form onSubmit={grant} className="row" style={{ gap: 6, flexWrap: "nowrap" }}>
<span className="num" style={{ minWidth: 28 }}>
{user.credits}
</span>
<label className="sr-only" htmlFor={`delta-${user.id}`}>
Kredit jóváírása
</label>
<input
id={`delta-${user.id}`}
className="inp"
style={{ width: 76, minHeight: 36 }}
inputMode="numeric"
placeholder="+10"
value={delta}
onChange={(e) => setDelta(e.target.value)}
/>
<button type="submit" className="btn btn-sm" disabled={busy || !delta}>
Jóváír
</button>
</form>
{status && (
<span className={status.ok ? "msg msg-ok" : "msg msg-error"} role="status">
{status.text}
</span>
)}
</td>
<td className="num">{user.charts}</td>
<td className="num">{formatDate(user.created_at)}</td>
<td className="num">{formatDate(user.last_login_at, true)}</td>
</tr>
);
}