Skip to content

Commit e995ee0

Browse files
Miriaddashboard
andcommitted
fix: fail-closed proxy when Supabase not configured
- Proxy redirects to login when env vars missing (never skip auth) - Browser client only uses NEXT_PUBLIC_ vars (non-prefixed not exposed) Co-authored-by: dashboard <dashboard@miriad.systems>
1 parent 44c8b67 commit e995ee0

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lib/supabase/client.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ import { createBrowserClient } from "@supabase/ssr";
22

33
/**
44
* Creates a Supabase client for use in Client Components (browser).
5-
* Note: NEXT_PUBLIC_ prefix is required for browser access.
6-
* Falls back to non-prefixed names for flexibility.
5+
* Requires NEXT_PUBLIC_ prefixed env vars (exposed to browser by Next.js).
76
*/
87
export function createClient() {
9-
const supabaseUrl =
10-
process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL;
11-
const supabaseAnonKey =
12-
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || process.env.SUPABASE_ANON_KEY;
8+
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
9+
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
1310

1411
if (!supabaseUrl || !supabaseAnonKey) {
1512
throw new Error(
16-
"Missing Supabase environment variables",
13+
"Missing NEXT_PUBLIC_SUPABASE_URL or NEXT_PUBLIC_SUPABASE_ANON_KEY environment variables",
1714
);
1815
}
1916

proxy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ export async function proxy(request: NextRequest) {
1111
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || process.env.SUPABASE_ANON_KEY;
1212

1313
if (!supabaseUrl || !supabaseAnonKey) {
14-
// No Supabase configured — allow access without auth
14+
// Auth not configured — block access to dashboard
15+
const url = request.nextUrl.clone();
16+
url.pathname = "/dashboard/login";
17+
if (request.nextUrl.pathname !== "/dashboard/login") {
18+
return NextResponse.redirect(url);
19+
}
1520
return supabaseResponse;
1621
}
1722

0 commit comments

Comments
 (0)