© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
12 replies
Ruyy

NextJs Supabase SSR rate limit with cache wrapper...

Hey everyone 👋,

I've been working with Supabase in my Next.js projects and ran into an issue with constant refetching, leading to rate limits (HTTP 429). I'm using the @supabase/ssr package, and my goal is to reduce the number of requests by caching the authenticated user data.

I've implemented a cached function in Next.js to get the authenticated user data like this:

import { createSupabaseServerClient } from "@/lib/database/server"
import { cookies } from "next/headers"
import { cache } from "react"


export const getAuthedUser = cache(async () => {
  const cookieStore = cookies()
  const supabase = createSupabaseServerClient(cookieStore)

  const { data: { user } } = await supabase.auth.getUser()

  if (!user) {
    return null;
  }

  return user;
})
import { createSupabaseServerClient } from "@/lib/database/server"
import { cookies } from "next/headers"
import { cache } from "react"


export const getAuthedUser = cache(async () => {
  const cookieStore = cookies()
  const supabase = createSupabaseServerClient(cookieStore)

  const { data: { user } } = await supabase.auth.getUser()

  if (!user) {
    return null;
  }

  return user;
})


However, despite caching, I'm still facing constant refetching and subsequent rate-limiting issues. How can I optimize this to bypass the constant refetching and prevent rate limits?

}
 [AuthApiError: Rate limit exceeded] {
  __isAuthError: true,
  name: 'AuthApiError',
  status: 429
}
}
 [AuthApiError: Rate limit exceeded] {
  __isAuthError: true,
  name: 'AuthApiError',
  status: 429
}


I'd appreciate any insights or suggestions on how to handle this more efficiently. Thanks in advance! 🙌
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Supabase JS rate limit
SupabaseSSupabase / help-and-questions
4mo ago
redux-next-wrapper with supabase v2 ssr
SupabaseSSupabase / help-and-questions
4y ago
Rate limiting with Supabase + Next.js SSR
SupabaseSSupabase / help-and-questions
2mo ago
RequestAsyncStorage error with NextJS 14 and @supabase/ssr
SupabaseSSupabase / help-and-questions
3y ago