SupabaseS
Supabase2mo ago
lp

Next Js 16, Data-Access-Layer with auth check

Hello, I am not sure if this is the right place to ask about it but I am using next 16 with cache components and inside my data access layer I make sure my user are auth indeed.

export async function AppHeaderUserMenu() {
  cacheLife({ stale: 3600 }); // Cache for 1 hour (3600 seconds)
  const authService = createAuthService();
  const profileService = createProfileService();

  // Get user ID from JWT claims (fast, local check)
  const userIdResult = await authService.getCurrentUser();

  if (isErr(userIdResult)) {
    redirect("/login");
  }

  const userId = userIdResult.data;

  // Fetch profile from database
  const profileResult = await profileService.getProfileById(userId);

  if (isErr(profileResult)) {
    redirect("/login");
  }

  const profile = profileResult.data;

  return <AppHeaderUserMenuDropdown profile={profile} />;
}


I am trying to cache user's profile but since profile require auth check I cannot cache and even with use cache: private, it does not work, idk why use cache: private does not work at alll...

THe right way I should do so is that I cannot cache the component directly since they require auth check so I should maybe only cache the profile and not component and the profile maybe use cache private too?

Let me know, I am pretty confused with those new directives and integrating with supabase!
Was this page helpful?