Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabaseβ€’6mo agoβ€’
18 replies
axelis

Auth and protected pages

Hello guys i have a question, im currently building a saas project with nextjs , supabase .Im using the ssr client, middleware , server architecture to authenticate the user, and i am wondering if i need to use

const supabase = await createClient();
  const { data, error } = await supabase.auth.getUser();
  if (error || !data?.user) {
    redirect("/login");
  }
const supabase = await createClient();
  const { data, error } = await supabase.auth.getUser();
  if (error || !data?.user) {
    redirect("/login");
  }


in every page because even if i dont use it i cant access the pages since there is the redirect to login with middleware but is this safe? because i think it only checks for the session it doesnt actually check if the user is authenticated,

also, if i want to hide my navbar if the user is not authenticated do i need to do the auth.getUser() again? wont that do 1 extra auth call in every page call?
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

Auth redirects to protected route
SupabaseSSupabase / help-and-questions
4y ago
Protected columns?
SupabaseSSupabase / help-and-questions
4y ago
Supabase UI Social Auth not redirecting to protected route
SupabaseSSupabase / help-and-questions
3w ago
Protected schema trigger
SupabaseSSupabase / help-and-questions
3y ago