You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently I just started to learn sveltekit + supabase, and so far it is good experience.
But now i'm facing a problem where when i enable the RLS, it's not allowing me to fetch the data.
previously i was at impression that this is the problem with my RLS, but it turned out when i try it in my refine.dev apps, its working perfectly, so i think this is the problem with how i fetch the data from my sveltekit apps.
is there anyone can help tell me where im doing wrong?
+hooks.server.ts
import{PUBLIC_SUPABASE_URL,PUBLIC_SUPABASE_ANON_KEY}from'$env/static/public';import{createServerClient}from'@supabase/ssr';import{redirect,typeHandle}from'@sveltejs/kit';import{sequence}from'@sveltejs/kit/hooks';constcreateSupabaseClient: Handle=async({ event, resolve })=>{event.locals.supabase=createServerClient(PUBLIC_SUPABASE_URL,PUBLIC_SUPABASE_ANON_KEY,{cookies: {get: (key)=>event.cookies.get(key),// NOTE: defaulting path to '/' here to support Sveltekit v2 which requires it to be// specified.set: (key,value,options)=>{event.cookies.set(key,value,{path: '/', ...options});},remove: (key,options)=>{event.cookies.delete(key,{path: '/', ...options});}}});/** * a little helper that is written for convenience so that instead * of calling `const { data: { session }} = await supabase.auth.getSession()` * you just call this `await getSession()` */event.locals.getSession=async()=>{const{data: { session }}=awaitevent.locals.supabase.auth.getSession();returnsession;};if(event.route.id?.startsWith('/(auth)')){if(!(awaitevent.locals.getSession()))throwredirect(302,'/login');}returnresolve(event,{filterSerializedResponseHeaders(name){// supabase needs the content-range headerreturnname==='content-range';}});};exportconsthandle=sequence(createSupabaseClient);
importtype{PageLoad}from'./$types';import{supabaseClient}from'$lib/supabaseClient';constpageSize=10;constpageNumber=1;// Calculate the offset based on the page size and page numberconstoffset=(pageNumber-1)*pageSize;exportconstload=(async()=>{returnawaitsupabaseClient.from("profiles").select("*").range(offset,offset+pageSize-1).limit(pageSize);})satisfiesPageLoad;
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Guys
Recently I just started to learn sveltekit + supabase, and so far it is good experience.
But now i'm facing a problem where when i enable the RLS, it's not allowing me to fetch the data.
previously i was at impression that this is the problem with my RLS, but it turned out when i try it in my refine.dev apps, its working perfectly, so i think this is the problem with how i fetch the data from my sveltekit apps.
is there anyone can help tell me where im doing wrong?
+hooks.server.ts
supabaseclient.ts
+page.ts
Beta Was this translation helpful? Give feedback.
All reactions