feat(confidence-engine): establish authenticated product boundary
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user