From 43f22c398069bacedd74f4e0814f4ecb6751d81a Mon Sep 17 00:00:00 2001 From: "Alex Pooley (@zuedev)" Date: Wed, 13 May 2026 17:16:23 +0100 Subject: middleware to proxy --- .../red-right-hand/174bg.net/src/middleware.js | 30 ---------------------- communities/red-right-hand/174bg.net/src/proxy.js | 30 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 30 deletions(-) delete mode 100644 communities/red-right-hand/174bg.net/src/middleware.js create mode 100644 communities/red-right-hand/174bg.net/src/proxy.js (limited to 'communities/red-right-hand/174bg.net') diff --git a/communities/red-right-hand/174bg.net/src/middleware.js b/communities/red-right-hand/174bg.net/src/middleware.js deleted file mode 100644 index 59312c6..0000000 --- a/communities/red-right-hand/174bg.net/src/middleware.js +++ /dev/null @@ -1,30 +0,0 @@ -import { NextResponse } from "next/server"; - -export async function middleware(request) { - let session = null; - - try { - const internalUrl = - process.env.BETTER_AUTH_URL_INTERNAL || "http://localhost:3000"; - const res = await fetch(new URL("/api/auth/get-session", internalUrl), { - headers: { - cookie: request.headers.get("cookie") ?? "", - }, - }); - session = await res.json(); - } catch { - // If session check fails, treat as unauthenticated - } - - if (!session?.user) { - const loginUrl = new URL("/login", request.url); - loginUrl.searchParams.set("callbackUrl", request.nextUrl.pathname); - return NextResponse.redirect(loginUrl); - } - - return NextResponse.next(); -} - -export const config = { - matcher: ["/secure/:path*"], -}; diff --git a/communities/red-right-hand/174bg.net/src/proxy.js b/communities/red-right-hand/174bg.net/src/proxy.js new file mode 100644 index 0000000..dc0fa42 --- /dev/null +++ b/communities/red-right-hand/174bg.net/src/proxy.js @@ -0,0 +1,30 @@ +import { NextResponse } from "next/server"; + +export async function proxy(request) { + let session = null; + + try { + const internalUrl = + process.env.BETTER_AUTH_URL_INTERNAL || "http://localhost:3000"; + const res = await fetch(new URL("/api/auth/get-session", internalUrl), { + headers: { + cookie: request.headers.get("cookie") ?? "", + }, + }); + session = await res.json(); + } catch { + // If session check fails, treat as unauthenticated + } + + if (!session?.user) { + const loginUrl = new URL("/login", request.url); + loginUrl.searchParams.set("callbackUrl", request.nextUrl.pathname); + return NextResponse.redirect(loginUrl); + } + + return NextResponse.next(); +} + +export const config = { + matcher: ["/secure/:path*"], +}; -- cgit v1.2.3