Next.js Discord

Discord Forum

Next js + Supabase Cache

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
how to add caching to supabase functions tags

  const supabase = SupabaseServerComponent();
  const { data, error } = await supabase.from("User").select("UserRole(Role(permissions))").eq("uid", userData.user.id).single();

i want to cache that

Note : export revalidate doesnt work
export revalidate = 37000

i doesnt cache it when i try build version of project
i want to have access to these stuff in fetch method
    next: {
      revalidate: 7200,
      tags: [`get-user-${uid}`],
    },


so is there a wrapper or something to wrapper non fetch method or idk what they are called to cache it
Note one more thing that may help supabase does use postgrest which run a fetch method i can see it in console of my api the fetch request but idk how to access or doo something with

20 Replies

Catla
hello
did u find an answer ??
Catla
plzzz help me ive been stuck on this for hours
@West African Lion
West African LionOP
on sec i forgot problem XD
Catla
okk
West African LionOP
Catla
oh yes ive seen it
so there is no other solution than to rewrite the entire fetch ?
West African LionOP
well ya or just write apis that can handle what ever it get passed to it
if u know what i mean
what i did in my own projects is i wrote apis which can handle alot of condition and stuff and i just cach that fetch method
Catla
hmm ok thx
West African LionOP
sry i couldn't help you
but i couldn't find anything related to this problem
Catla
no problem really
if i find a better solution i will tell u
Catla
ok i found it !
    const supabase = createClient(process.env.NEXT_PUBLIC_SUPABASE_URL, process.env.SUPABASE_SECRET_KEY , {global : {fetch: e => fetch(e , { next: { revalidate: 0 } , headers: {apikey: process.env.SUPABASE_SECRET_KEY , authorization: `Bearer ${process.env.SUPABASE_SECRET_KEY}`} } )}})
i made a custom fetch function so we just have to change the usual props