basic login implementation at localhost:3000//login

This commit is contained in:
Domonkos
2026-01-27 18:32:29 +01:00
parent 6dbacca017
commit 086e5a867d
16 changed files with 234 additions and 34 deletions

View File

@@ -1,6 +1,7 @@
import { TopBar, BackLink } from "../../../components/shell/TopBar";
export default function AboutPage() {
// @ts-ignore
return (
<div>
<TopBar title="Info" left={<BackLink href="/" />} />

View File

@@ -0,0 +1,38 @@
import { redirect } from "next/navigation";
import { cookies } from "next/headers";
export default async function AdminPage() {
const cookieHeader = (await cookies())
.getAll()
.map(({ name, value }) => `${name}=${value}`)
.join("; ");
const res = await fetch(`${process.env.BACKEND_URL}/api/me`, {
headers: { cookie: cookieHeader },
cache: "no-store",
redirect: "manual", // IMPORTANT: dont follow to /login
});
// Spring might answer 302 to /login when unauthenticated
if (res.status === 401 || res.status === 302) redirect("/login");
if (!res.ok) {
const text = await res.text();
throw new Error(`Failed to load session: ${res.status} ${text.slice(0, 200)}`);
}
const contentType = res.headers.get("content-type") ?? "";
if (!contentType.includes("application/json")) {
// we got HTML (login page) or something else
redirect("/login");
}
const me = await res.json();
return (
<main>
<h1>Admin</h1>
<pre>{JSON.stringify(me, null, 2)}</pre>
</main>
);
}

View File

@@ -0,0 +1,7 @@
import { redirect } from "next/navigation";
export default function LoginPage() {
const backend = process.env.BACKEND_URL!;
const returnTo = encodeURIComponent("http://localhost:3000/admin");
redirect(`${backend}/login-redirect?redirect=${returnTo}`);
}