feat(confidence-engine): establish authenticated product boundary

This commit is contained in:
2026-09-08 16:30:07 +01:00
parent 1c17452bee
commit 30bf44f2e5
22 changed files with 487 additions and 8 deletions
+13
View File
@@ -0,0 +1,13 @@
import { getAuthenticatedUser } from "@/lib/supabase/server.js";
export function unauthorizedResponse() {
return Response.json({ error: "Unauthorized" }, { status: 401 });
}
export function withAuthenticatedApi(handler) {
return async function authenticatedApiHandler(request, context) {
const user = await getAuthenticatedUser();
if (!user) return unauthorizedResponse();
return handler(request, context);
};
}
+14
View File
@@ -0,0 +1,14 @@
"use client";
import { createBrowserClient } from "@supabase/ssr";
export function createClient() {
return createBrowserClient(
process.env.NEXT_PUBLIC_SUPABASE_URL,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
);
}
export function magicLinkRedirectTo(origin) {
return `${origin}/auth/callback`;
}
+33
View File
@@ -0,0 +1,33 @@
import { createServerClient } from "@supabase/ssr";
import { cookies } from "next/headers";
function getSupabaseConfig() {
return {
url: process.env.NEXT_PUBLIC_SUPABASE_URL,
key: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
};
}
export function createServerSupabaseClient() {
const cookieStore = cookies();
const { url, key } = getSupabaseConfig();
return createServerClient(url, key, {
cookies: {
getAll() {
return cookieStore.getAll();
},
setAll(cookiesToSet) {
try {
cookiesToSet.forEach(({ name, value, options }) => cookieStore.set(name, value, options));
} catch {
// Server Components cannot write cookies; middleware refreshes sessions.
}
},
},
});
}
export async function getAuthenticatedUser() {
const { data: { user } } = await createServerSupabaseClient().auth.getUser();
return user;
}