{
  "version": 3,
  "sources": ["ssg:https://framerusercontent.com/modules/nFXcsi7qNXwQese9BwLw/e4s4u1ZLr37fMpjuK6xu/useSupabaseClient.js"],
  "sourcesContent": ["// framer-backend-components/src/hooks/useSupabaseClient.ts\nimport{useState,useEffect,useMemo}from\"react\";export function useSupabaseClient(){const[client,setClient]=useState(null);const[isReady,setIsReady]=useState(false);// --- Read intended redirect PATH from query param ONCE ---\nconst intendedRedirectPath=useMemo(()=>{if(typeof window!==\"undefined\"){const params=new URLSearchParams(window.location.search);const redirect=params.get(\"redirect\");if(redirect&&redirect.startsWith(\"/\")){// Ensure it's a path\nconsole.log(\"[useSupabaseClient] Found intended redirect path in query params:\",redirect);return redirect// Return the path like \"/dashboard/account\"\n;}}return null// No valid redirect param found\n;},[]);useEffect(()=>{if(typeof window===\"undefined\"){console.log(\"useSupabaseClient: Skipping effect on server.\");setIsReady(true)// Mark ready immediately on server\n;return;}const initialClient=window.__supabaseClient;const initialReady=!!window.__supabaseReady;if(initialClient&&initialReady){console.log(\"useSupabaseClient: Found client/ready immediately on mount.\");setClient(initialClient);setIsReady(true);return;}console.log(`useSupabaseClient: Polling starting (Initial mount: client=${!!initialClient}, ready=${initialReady})`);let attempts=0;const maxAttempts=30;const interval=250;const intervalId=setInterval(()=>{const currentClient=window.__supabaseClient;const currentReady=!!window.__supabaseReady;if(currentClient&&currentReady){console.log(`useSupabaseClient: Found client/ready via polling on attempt ${attempts+1}.`);setClient(currentClient);setIsReady(true);clearInterval(intervalId);return;}attempts++;if(attempts>=maxAttempts){console.warn(`useSupabaseClient: Polling timed out. Client found: ${!!currentClient}, Ready flag found: ${!!currentReady}`);setIsReady(true);if(currentClient&&!client){setClient(currentClient);}clearInterval(intervalId);}},interval);return()=>clearInterval(intervalId);},[])// Empty dependency array ensures client-side execution after mount\n;// --- Helper Functions ---\nconst getRedirectUrl=()=>{// Ensure it only runs client-side\nif(typeof window!==\"undefined\"){// Return the actual URL construction\nreturn window.location.origin+window.location.pathname+window.location.search;}// Return an empty string or handle server case if necessary,\n// though actions requiring it shouldn't run server-side.\nconsole.warn(\"getRedirectUrl called in non-browser environment.\");return\"\";};// --- Action Functions ---\nconst signInWithProvider=async provider=>{if(!client)throw new Error(\"Supabase client not available.\");if(!isReady)throw new Error(\"Supabase client not ready.\");// --- Construct Absolute Redirect URL ---\nlet absoluteRedirectTo=undefined;if(typeof window!==\"undefined\"){const origin1=window.location.origin// Get \"https://your-site.framer.app\"\n;if(intendedRedirectPath){// Combine origin and path\nabsoluteRedirectTo=origin1+intendedRedirectPath;}else{// Fallback: Use the current page (origin + path) if no specific redirect was intended\n// This is often the default behavior Supabase aims for anyway\nabsoluteRedirectTo=origin1+window.location.pathname+window.location.search;}}// If window isn't defined (shouldn't happen here), absoluteRedirectTo remains undefined\n//TEMP: set a fixed redirect path that will act as coordinator to send the user to the correct place based on their profile state\nabsoluteRedirectTo=origin+\"/auth/callback\";console.log(`[useSupabaseClient] Calling signInWithOAuth for ${provider}. Absolute RedirectTo:`,absoluteRedirectTo||\"<Default - Likely Origin>\");// --- End Construct Absolute URL ---\nconst{error}=await client.auth.signInWithOAuth({provider:provider,options:{redirectTo:absoluteRedirectTo}});if(error)throw error;};// Specific provider functions now call the generic one\nconst signInWithGoogle=()=>signInWithProvider(\"google\");const signInWithApple=()=>signInWithProvider(\"apple\");const signOut=async()=>{if(!client)throw new Error(\"Supabase client not available.\");if(!isReady)throw new Error(\"Supabase client not ready.\");const{error}=await client.auth.signOut();if(error)throw error// Re-throw for component to handle\n;console.log(\"[useSupabaseClient] Sign out successful.\");};// --- Return Value ---\nreturn{client,isReady,signInWithGoogle,signInWithApple,signOut,intendedRedirectPath};}\nexport const __FramerMetadata__ = {\"exports\":{\"useSupabaseClient\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./useSupabaseClient.map"],
  "mappings": "4GAAAA,IACqD,SAASC,GAAmB,CAAC,GAA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OAAO,OAAS,IACZ,OAAO,SAAS,OAAO,OAAO,SAAS,SAAS,OAAO,SAAS,QAEvE,QAAQ,KAAK,mDAAmD,EAAQ,IAClEC,EAAmB,MAAMC,GAAU,CAAC,GAAG,CAAClB,EAAO,MAAM,IAAI,MAAM,gCAAgC,EAAE,GAAG,CAACG,EAAQ,MAAM,IAAI,MAAM,4BAA4B,EAC/J,IAAIgB,EAA6B,GAAG,OAAO,OAAS,IAAY,CAAC,IAAMC,EAAQ,OAAO,SAAS,OAC3Ff,EACJc,EAAmBC,EAAQf,EAE3Bc,EAAmBC,EAAQ,OAAO,SAAS,SAAS,OAAO,SAAS,MAAQ,CAE5ED,EAAmB,OAAO,iBAAiB,QAAQ,IAAI,mDAAmDD,CAAQ,yBAAyBC,GAAoB,2BAA2B,EAC1L,GAAK,CAAC,MAAAE,CAAK,EAAE,MAAMrB,EAAO,KAAK,gBAAgB,CAAC,SAASkB,EAAS,QAAQ,CAAC,WAAWC,CAAkB,CAAC,CAAC,EAAE,GAAGE,EAAM,MAAMA,CAAM,EAGjI,MAAM,CAAC,OAAArB,EAAO,QAAAG,EAAQ,iBAFC,IAAIc,EAAmB,QAAQ,EAEf,gBAFuC,IAAIA,EAAmB,OAAO,EAErD,QAFqE,SAAS,CAAC,GAAG,CAACjB,EAAO,MAAM,IAAI,MAAM,gCAAgC,EAAE,GAAG,CAACG,EAAQ,MAAM,IAAI,MAAM,4BAA4B,EAAE,GAAK,CAAC,MAAAkB,CAAK,EAAE,MAAMrB,EAAO,KAAK,QAAQ,EAAE,GAAGqB,EAAM,MAAMA,EACpT,QAAQ,IAAI,0CAA0C,CAAE,EACM,qBAAAhB,CAAoB,CAAE",
  "names": ["init_ssg_sandbox_shims", "useSupabaseClient", "client", "setClient", "ye", "isReady", "setIsReady", "intendedRedirectPath", "se", "redirect", "ue", "initialClient", "initialReady", "attempts", "maxAttempts", "intervalId", "currentClient", "currentReady", "getRedirectUrl", "signInWithProvider", "provider", "absoluteRedirectTo", "origin1", "error"]
}
