From 6abe450f1d323508d560144dc38f45e749de5f5a Mon Sep 17 00:00:00 2001 From: makearmy Date: Tue, 30 Sep 2025 22:38:25 -0400 Subject: [PATCH] added splash page --- app/page.tsx | 154 +++++++++++--------------------------------------- middleware.ts | 53 ++++++++++------- 2 files changed, 66 insertions(+), 141 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 8c488bd9..245481bc 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,129 +1,41 @@ -import { Button } from "@/components/ui/button"; -import { Card, CardContent } from "@/components/ui/card"; -import Link from "next/link"; +// app/page.tsx +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"; + +export default async function HomePage() { + // If already signed in, go straight to the app + const ck = await cookies(); + const at = ck.get("ma_at")?.value; + if (at) redirect("/portal"); -export default function Home() { return ( -
-

Laser Everything Community Database

+
+
+

MakeArmy

+

+ Free to use. Manage laser rigs, settings, and projectsβ€”all in one place. +

+
-
- - -

Fiber Laser Settings

-

- Browse and submit settings for fiber laser engraving. -

- - - -
-
+
+
+

Create an account

+ {/* Uses your existing sign-up component */} + +
- - -

CO2 Galvo Settings

-

- Settings for CO2 Galvo laser machines. -

- - - -
-
+
+

Sign in

+ {/* Uses your existing sign-in component */} + +
+
- - -

CO2 Gantry Settings

-

- Settings for CO2 Gantry laser systems. -

- - - -
-
- - - -

UV Laser Settings

-

- Settings for UV laser engraving and marking. -

- - - -
-
- - - -

Materials and Coatings

-

- Explore materials and surface coatings along with their laser safety classifications. -

-
- - - - - - -
-
-
- - - -

Laser Source Database

-

- Technical specs and info on various laser sources. -

- - - -
-
- - - -

Projects Database

-

- Community-submitted projects and guides. -

- - - -
-
- - {/* πŸ”½ NEW FILE DOWNLOAD SECTION πŸ”½ */} - - -

Downloadable Files

-

- Browse and download shared files from the server. -

- - - -
-
- - {/* πŸ”½ NEW BUYING GUIDE CARD πŸ”½ */} - - -

Buying Guide

-

- Reviews and recommendations for laser products and accessories. -

- - - -
-
-
+
+ We only use cookies strictly necessary to operate the site (e.g., your sign-in session). +
); } - diff --git a/middleware.ts b/middleware.ts index c0ddfa01..ac77008f 100644 --- a/middleware.ts +++ b/middleware.ts @@ -5,7 +5,11 @@ import { NextResponse, NextRequest } from "next/server"; * Public pages that should remain reachable without being signed in. * Everything else is considered protected (including most /api/*). */ - const PUBLIC_PAGES = new Set(["/auth/sign-in", "/auth/sign-up"]); + const PUBLIC_PAGES = new Set([ + "/", // ← splash page is public + "/auth/sign-in", + "/auth/sign-up", + ]); /** * API paths that are explicitly allowed without auth. @@ -17,8 +21,7 @@ import { NextResponse, NextRequest } from "next/server"; ]; /** Directus base (used to remotely validate the token after restarts). */ - const DIRECTUS = - (process.env.NEXT_PUBLIC_API_BASE_URL || process.env.DIRECTUS_URL || "").replace(/\/$/, ""); + const DIRECTUS = (process.env.NEXT_PUBLIC_API_BASE_URL || process.env.DIRECTUS_URL || "").replace(/\/$/, ""); /** Helper: does the path start with any prefix in a list? */ function startsWithAny(pathname: string, prefixes: string[]) { @@ -47,22 +50,32 @@ import { NextResponse, NextRequest } from "next/server"; } } - /** Build redirect to /auth/sign-in?reauth=1&next=, and clear auth markers. */ - function kickToSignIn(req: NextRequest) { + /** + * Build redirect to /auth/sign-in?next=. + * Only set reauth=1 (and clear cookies) when opts.reauth === true. + */ + function kickToSignIn(req: NextRequest, opts?: { reauth?: boolean }) { + const wantReauth = !!opts?.reauth; + const orig = new URL(req.url); const next = orig.pathname + (orig.search || ""); + const url = new URL(req.url); url.pathname = "/auth/sign-in"; url.search = ""; - url.searchParams.set("reauth", "1"); + if (wantReauth) url.searchParams.set("reauth", "1"); url.searchParams.set("next", next); const res = NextResponse.redirect(url); - // Clear tokens so the very next /auth/* request is truly unauthenticated - res.cookies.set("ma_at", "", { maxAge: 0, path: "/" }); - res.cookies.set("ma_v", "", { maxAge: 0, path: "/" }); // throttle marker - // If you also use a refresh token, clear it here too: - // res.cookies.set("ma_rt", "", { maxAge: 0, path: "/" }); + + // Only clear auth markers in true re-auth scenarios + if (wantReauth) { + res.cookies.set("ma_at", "", { maxAge: 0, path: "/" }); + res.cookies.set("ma_v", "", { maxAge: 0, path: "/" }); // throttle marker + // If you also use a refresh token, clear it here too: + // res.cookies.set("ma_rt", "", { maxAge: 0, path: "/" }); + } + return res; } @@ -90,9 +103,9 @@ import { NextResponse, NextRequest } from "next/server"; isAuthRoute && (url.searchParams.get("reauth") === "1" || url.searchParams.get("force") === "1"); - // If unauthenticated and the route is protected, send to sign-in (with next + reauth) + // If unauthenticated and the route is protected, send to sign-in WITHOUT reauth if (!token && isProtected) { - return kickToSignIn(req); + return kickToSignIn(req, { reauth: false }); } // If we have a token, perform local expiry check. @@ -100,8 +113,7 @@ import { NextResponse, NextRequest } from "next/server"; const exp = jwtExp(token); const expired = !exp || exp * 1000 <= Date.now(); - // If it's an auth route and token looks valid, keep your existing UX: - // bounce away from auth pages β€” unless this is a forced reauth. + // If it's an auth route and token looks valid, bounce away from auth pages β€” unless this is a forced reauth. if (isAuthRoute && !expired && !forceAuth) { url.pathname = "/portal"; url.search = ""; @@ -111,7 +123,8 @@ import { NextResponse, NextRequest } from "next/server"; // If protected route: enforce validity if (isProtected) { if (expired) { - return kickToSignIn(req); + // True reauth + return kickToSignIn(req, { reauth: true }); } // ── Throttled remote validation (catches server restarts / revoked tokens) @@ -131,8 +144,8 @@ import { NextResponse, NextRequest } from "next/server"; }); if (!r.ok) { - // Token no longer valid on the server β†’ force re-auth, carry next - return kickToSignIn(req); + // Token no longer valid on the server β†’ true reauth, carry next + return kickToSignIn(req, { reauth: true }); } // Cache the success for ~1 minute to avoid hammering Directus @@ -146,7 +159,7 @@ import { NextResponse, NextRequest } from "next/server"; return res; } catch { // If Directus is unreachable, be conservative and require re-auth - return kickToSignIn(req); + return kickToSignIn(req, { reauth: true }); } } } @@ -213,7 +226,7 @@ import { NextResponse, NextRequest } from "next/server"; } function isPublicPath(pathname: string): boolean { - // 1) Public pages (auth screens) + // 1) Public pages (root splash & auth screens) if (PUBLIC_PAGES.has(pathname)) return true; // 2) Static assets / internals