Hello, I am using supabase for auth and storage and the new cached components of nextjs 16. All data access goes through my DAL. The authentication happens at several stages. I have a basic getClaims() call in my proxy as a first authorization layer which redirects unauthenticated users to the login page when they access a protected route. Ive read that this is not enough so each protected route also enforces authroization. Furthermore, each server action does as well as the DAL.
As per the docs the getClaims() calls get cached. However I notice weirdly high amount of requests to supabase simply by moving around my app and reloading. Is this normal or am I doing something wrong? I think 320 requests in 15 minutes from a single user doing nothing other than navigating around the app and his profile with 80 of them being auth requests seems bad.
I think the rest of the requests are from the profile data being fetched on every profile reload because I cannot cache it due to creating supabase client which requires cookies.
This is an example of a DAL function and how I tried to cache it but it doesnt seem to work.
const getUserCollectionsCached = async (userId: string, authenticated: boolean) => {
'use cache: private';
cacheLife('hours');
cacheTag(`user-collections-${userId}`);
if (!authenticated) throw new UnauthorizedError("User not authorized");
console.log(`[DAL][Collection][CACHE CHECKKKKK] Fetching collections for user: ${userId}`);
const supabase = await createClient();
const { data, error } = await supabase
.from("collection")
.select("*")
.eq("owner_id", userId)
.is("deleted_at", null);
if (error) {
console.error(`[ERROR][DAL][Collection_getUserCollections] User: ${userId} |`, error);
throw new InfraError("Failed to retrieve collections");
}
return data;
};
The user is experiencing a high number of requests to Supabase when navigating their app, with 320 requests in 15 minutes, including 80 auth requests. They suspect caching issues with their Data Access Layer (DAL) and are seeking advice on reducing the request count.
Is there another way to handle this?