aboutsummaryrefslogtreecommitdiff
path: root/communities/red-right-hand/174bg.net/src/proxy.js
diff options
context:
space:
mode:
authorAlex Pooley (@zuedev) <zuedev@gmail.com>2026-05-13 17:16:23 +0100
committerAlex Pooley (@zuedev) <zuedev@gmail.com>2026-05-13 17:16:23 +0100
commit43f22c398069bacedd74f4e0814f4ecb6751d81a (patch)
tree331f08f434f6a92fc6f8884e1926d96d63601cf8 /communities/red-right-hand/174bg.net/src/proxy.js
parent5d0be005a07e781e2088d6427e628ff9157d91ee (diff)
downloadunnamed-group-43f22c398069bacedd74f4e0814f4ecb6751d81a.tar
unnamed-group-43f22c398069bacedd74f4e0814f4ecb6751d81a.tar.gz
unnamed-group-43f22c398069bacedd74f4e0814f4ecb6751d81a.tar.bz2
unnamed-group-43f22c398069bacedd74f4e0814f4ecb6751d81a.tar.xz
unnamed-group-43f22c398069bacedd74f4e0814f4ecb6751d81a.zip
middleware to proxy
Diffstat (limited to 'communities/red-right-hand/174bg.net/src/proxy.js')
-rw-r--r--communities/red-right-hand/174bg.net/src/proxy.js30
1 files changed, 30 insertions, 0 deletions
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*"],
+};