sign in and register fixes for looped and forwarded pages

This commit is contained in:
makearmy 2025-10-02 14:21:12 -04:00
parent 5257a0d2fe
commit ffccff85d4
6 changed files with 68 additions and 20 deletions

View file

@ -3,19 +3,35 @@ import { cookies } from "next/headers";
import { redirect } from "next/navigation";
import SignIn from "@/app/auth/sign-in/sign-in";
import SignUp from "@/app/auth/sign-up/sign-up";
import { isJwtValid } from "@/lib/jwt";
export default async function HomePage() {
// If already signed in, go straight to the app
type SearchParams = { [key: string]: string | string[] | undefined };
export default async function HomePage({
searchParams,
}: {
searchParams?: SearchParams;
}) {
// If already signed in with a VALID token, go straight to the app
const ck = await cookies();
const at = ck.get("ma_at")?.value;
if (at) redirect("/portal");
if (isJwtValid(at)) redirect("/portal");
const reauth = searchParams?.reauth === "1";
return (
<main className="mx-auto max-w-5xl px-4 py-12">
{reauth && (
<p className="mb-6 rounded-md border bg-yellow-50 p-3 text-sm text-yellow-900">
Your session expired. Please sign in again.
</p>
)}
<section className="mb-10 text-center">
<h1 className="text-3xl font-bold tracking-tight">MakeArmy</h1>
<p className="mt-2 text-base text-muted-foreground">
Free to use. Manage laser rigs, settings, and projectsall in one place.
Free to use. Manage laser rigs, settings, and projectsall in one
place.
</p>
</section>
@ -29,12 +45,13 @@ export default async function HomePage() {
<div className="rounded-lg border p-6">
<h2 className="mb-3 text-lg font-semibold">Sign in</h2>
{/* Uses your existing sign-in component */}
<SignIn nextPath="/portal" reauth={false} />
<SignIn nextPath="/portal" reauth={reauth} />
</div>
</section>
<section className="mt-8 text-center text-xs text-muted-foreground">
We only use cookies strictly necessary to operate the site (e.g., your sign-in session).
We only use cookies strictly necessary to operate the site (e.g., your
sign-in session).
</section>
</main>
);