File size: 1,229 Bytes
ff34739
 
b303f51
ff34739
 
 
 
 
 
 
 
 
b303f51
 
 
 
ff34739
 
b303f51
ff34739
 
 
b303f51
ff34739
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { basicAuthOk } from "@/lib/auth";

/**
 * Optional basic-auth gate for public deployments. If STUDIO_AUTH_USER and
 * STUDIO_AUTH_PASS are set, every request must carry matching Basic credentials;
 * if they're unset, the app is open (local / private-network use).
 *
 * Studio spawns paid Claude calls and runs a pipeline, so DO set these when the
 * app is reachable from the public internet. The browser attaches the cached
 * Basic credentials to fetch and EventSource (SSE) automatically after sign-in.
 *
 * The FASTQ upload route is excluded from the matcher: Next caps a request body
 * that flows through middleware at 10 MiB (which silently truncates large FASTQ),
 * so that route runs `basicAuthOk` itself instead (see src/lib/auth.ts).
 */
export const config = {
  matcher: ["/((?!_next/static|_next/image|favicon.ico|api/projects/[^/]+/inputs/upload).*)"],
};

export function proxy(request: NextRequest) {
  if (basicAuthOk(request)) return NextResponse.next();
  return new NextResponse("Authentication required", {
    status: 401,
    headers: { "WWW-Authenticate": 'Basic realm="Seqcolyte Studio"' },
  });
}