Hi everyone!
I'm facing an issue with my Next.js project in production.
I have an API route called getCount that looks like this:
import { NextRequest, NextResponse } from "next/server";import { supabase } from "@/lib/supabaseClient";
export async function GET(request: NextRequest) { try { const count = await getCount();
return NextResponse.json(count); } catch (error) { // console.error(error); console.log("errorrrr"); return NextResponse.json({ error }); }}
const getCount = async () => { try { const { data, error } = await supabase .from("counter") .select("count") .eq("id", 1) .single();
if (error) throw error; return data.count; } catch (error: any) { console.error("Error getting count:", error.message); return 0; }};The API is quite simple—it fetches a single record from my Supabase database and returns the count value.
The problem is that it works locally as expected, but in production (hosted on Vercel), it only fetches the data once. After that, the data never updates, even though it changes in Supabase. The only way to get the updated value is by redeploying the app, which obviously isn’t convenient.
I suspect this might be a caching issue, but I'm not sure what I’m doing wrong.
How can I fix this?
Thanks!!