Based on the information provided in the knowledge sources, it appears that NextJS 15 has introduced some changes in how cookies can be modified, particularly when working with Supabase SSR. Let me explain the issue and provide some guidance:
In NextJS 15, cookies can only be modified in a Server Action or Route Handler. This is explicitly mentioned in the Next.js documentation (https://nextjs.org/docs/app/api-reference/functions/cookies#good-to-know):
HTTP does not allow setting cookies after streaming starts, so you must use .set in a Server Action (https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations) or Route Handler (https://nextjs.org/docs/app/building-your-application/routing/route-handlers).
To resolve this issue with Supabase SSR, you need to ensure that you're initializing the Supabase client within a function scope, not in the global scope. This is because the cookies are not available outside of an HTTP request context.
Here's an example of how you can modify your code to work with NextJS 15 and Supabase:
"use server"
import { createClient } from "@/utils/supabase/server";
export async function getLatestProjects() {
const supabase = createClient();
let { data: projects, error } = await supabase
.from('new_projects')
.select('*')
.order('end_date', { ascending: false })
.limit(10);
if (error) throw error;
return projects;
}
This approach is mentioned in a GitHub issue comment (https://github.com/vercel/next.js/issues/67191) discussing a similar problem.
Remember to only initialize the Supabase client inside functions where it has access to cookies. This ensures that the client is created within the correct request scope.