© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•14mo ago
wafflemaster123

Supabase auth recommended listeners?

Hey! On a NextJS app, is there any recommended practice on the front end for using auth listeners/hooks to always be able to reliable fetch the user logged in?

For example, let’s say we have a Navbar component which should show either:

1) logged in user’s icon (like initials such as B)
2) if not logged in, a log in button.

Currently I'm using a method which kind of fetches/does this check on every render of navbar hence it looks weird since on a full refresh the page loads but navbar part of user is still pending and loads in a few seconds.

useEffect(() => {
    async function getUser() {
      try {
        const {
          data: { user },
        } = await supabase.auth.getUser();
        console.log(user);
        
        const { data, error } = await supabase.auth.getSession()
        console.log(data);
        console.log(error);

        setUser(user);
      } catch (error) {
        console.error("Error fetching user:", error);
      } finally {
        setIsLoading(false);
      }
    }

    getUser();
}
useEffect(() => {
    async function getUser() {
      try {
        const {
          data: { user },
        } = await supabase.auth.getUser();
        console.log(user);
        
        const { data, error } = await supabase.auth.getSession()
        console.log(data);
        console.log(error);

        setUser(user);
      } catch (error) {
        console.error("Error fetching user:", error);
      } finally {
        setIsLoading(false);
      }
    }

    getUser();
}
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

Recommended Auth Solution for Supabase app?
SupabaseSSupabase / help-and-questions
2mo ago
supabase auth
SupabaseSSupabase / help-and-questions
3y ago
Supabase auth down?
SupabaseSSupabase / help-and-questions
3mo ago
supabase auth issue
SupabaseSSupabase / help-and-questions
4y ago