"use client"; import { createBrowserSupabaseClient, Session, } from "@supabase/auth-helpers-nextjs"; import { useRouter } from "next/navigation"; import { createContext, useEffect, useState } from "react"; import { SupabaseContextType } from "./types"; export const SupabaseContext = createContext( undefined ); export const SupabaseProvider = ({ children, session, }: { children: React.ReactNode; session: Session | null; }): JSX.Element => { const [supabase] = useState(() => createBrowserSupabaseClient()); const router = useRouter(); useEffect(() => { const { data: { subscription }, } = supabase.auth.onAuthStateChange(() => { router.refresh(); }); return () => { subscription.unsubscribe(); }; }, [router, supabase]); return ( <>{children} ); };