© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
2 replies
NuggetPirate

useSessionContext() + loading state?

What are some best practices on handling the time the session is being fetched?

Tried adding a loading state here but keep hitting the redirect /login path because session is null in the initial render. Is there an isFetching state I can pull from useSessionConetxt?

export const Home = ({ scenes }: { scenes: Scene[] }) => {
    // TODO display username somewhere
    const { session } = useSessionContext();
    const { profile, creatingProfile, setProfile } = useCustomerContext(); // active profile
    const { user, isLoading } = useUserInfo(session && session.user ? session.user.id : null)
    const router = useRouter();
    const { profile: profileQueryParam } = router.query;

    if (isLoading) {
        return (
            // tailwind center aligned full screen column in the middle
            <div className="flex flex-col items-center justify-center h-screen">
                <Loader>Loading</Loader>
            </div>
        )
    }

    if (!isLoading && !user) {
        router.push('/login');
        return null;
    }
export const Home = ({ scenes }: { scenes: Scene[] }) => {
    // TODO display username somewhere
    const { session } = useSessionContext();
    const { profile, creatingProfile, setProfile } = useCustomerContext(); // active profile
    const { user, isLoading } = useUserInfo(session && session.user ? session.user.id : null)
    const router = useRouter();
    const { profile: profileQueryParam } = router.query;

    if (isLoading) {
        return (
            // tailwind center aligned full screen column in the middle
            <div className="flex flex-col items-center justify-center h-screen">
                <Loader>Loading</Loader>
            </div>
        )
    }

    if (!isLoading && !user) {
        router.push('/login');
        return null;
    }
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

Cancelling statement due to statemtn timeout
SupabaseSSupabase / help-and-questions
7mo ago
Can I get loading state from data fetch?
SupabaseSSupabase / help-and-questions
4y ago
Loading problem
SupabaseSSupabase / help-and-questions
2mo ago
infinity loading
SupabaseSSupabase / help-and-questions
6mo ago