Files
ARTEX/web/src/proxy.ts
T
BaaRaiandAseemPrasad 99530c442a ci(web): satisfy and enforce Biome checks on post-#603 web tree (#655)
Regenerated cleanly on top of #603 (becc47a + reducers + #641/#660/W01/
openai-compatible) without touching Go files or locale JSONs:
- formats and organizes imports across web/ with Biome 2.5.1
- fixes blocking lint/a11y/promise/hook-dependency diagnostics (including
  public/logo.svg <title> required by lint/a11y/noSvgWithoutTitle)
- enforces blocking `npx biome ci .` in the web CI job.

Co-authored-by: AseemPrasad <aseemprasad0520@gmail.com>
2026-11-29 01:02:27 +01:00

33 lines
1.2 KiB
TypeScript

import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
const AUTH_PAGES = ["/login", "/setup"];
export function proxy(request: NextRequest) {
// Mock demo: no real login; allow every page (the client-side auth guard also allows through).
if (process.env.NEXT_PUBLIC_MOCK === "1") return NextResponse.next();
const { pathname } = request.nextUrl;
const token = request.cookies.get("artex_token")?.value;
const isAuthPage = AUTH_PAGES.some((p) => pathname === p || pathname.startsWith(`${p}/`));
// Not logged in → redirect to the login page
if (!token && !isAuthPage) {
return NextResponse.redirect(new URL("/login", request.url));
}
// Logged in while visiting the login/setup pages → redirect to the main UI
if (token && isAuthPage) {
return NextResponse.redirect(new URL("/function/tasks", request.url));
}
return NextResponse.next();
}
export const config = {
// Skip Next.js internal routes, API routes, favicon, and static files under public/ (images, fonts, etc.)
matcher: [
"/((?!_next/static|_next/image|favicon\\.ico|api/|.*\\.(?:png|jpg|jpeg|gif|webp|svg|ico|woff2?|ttf|otf)$).*)",
],
};