{"version":3,"file":"ReZero_UserDataProvider.NCyqE5VH.mjs","names":["createClient","_Fragment"],"sources":["https:/framerusercontent.com/modules/BRuVAbxUUCs6dSR82WEI/8DTfSC1gKHIdTDzbsoI3/ReZero_UserDataProvider.js"],"sourcesContent":["import{jsx as _jsx,Fragment as _Fragment}from\"react/jsx-runtime\";import{useEffect}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";import{createClient}from\"https://esm.sh/@supabase/supabase-js@2\";const emptyUserData={isLoading:false,isLoggedIn:false,provider:\"\",name:\"\",email:\"\",phone:\"\",birthdate:\"\",gender:\"\",interests:[]};function publishUserData(userData){console.log(\"[RZ] publishUserData\",userData.isLoggedIn);window.__rzUserData=userData;window.dispatchEvent(new CustomEvent(\"rzUserDataLoaded\",{detail:userData}));}function getNormalizedRedirectTarget(link){const trimmedLink=link.trim();if(!trimmedLink)return null;try{const targetUrl=new URL(trimmedLink,window.location.origin);return{href:targetUrl.origin===window.location.origin?`${targetUrl.pathname}${targetUrl.search}${targetUrl.hash}`:targetUrl.href,comparable:targetUrl.origin===window.location.origin?`${targetUrl.pathname}${targetUrl.search}${targetUrl.hash}`:targetUrl.href};}catch(error){console.error(\"[RZ] invalid profileCompletePath:\",trimmedLink,error);return null;}}/** @framerDisableUnlink */export default function ReZero_UserDataProvider(props){const{supabaseProjectId,supabaseAnonKey,tableName,profileCompletePath,profileCompleteMessage}=props;useEffect(()=>{if(!supabaseProjectId||!supabaseAnonKey){publishUserData(emptyUserData);return;}const supabaseUrl=`https://${supabaseProjectId}.supabase.co`;const supabase=createClient(supabaseUrl,supabaseAnonKey);window.__rzSupabase=supabase;let isMounted=true;let redirectHandled=false;async function notifyAccountLinked(session){const isOAuthCallback=window.location.hash.includes(\"access_token\")||window.location.search.includes(\"code=\");if(!isOAuthCallback)return;const identities=session.user.identities??[];const hasEmailIdentity=identities.some(i=>i.provider===\"email\");const hasOAuthIdentity=identities.some(i=>i.provider!==\"email\");if(hasEmailIdentity&&hasOAuthIdentity){alert(\"기존 이메일 계정과 소셜 계정이 연결됐습니다.\\n앞으로 두 방법 모두로 로그인하실 수 있어요.\");}}async function fetchUserDataWithSession(session){const{data,error}=await supabase.from(tableName||\"registrations\").select(\"*\").eq(\"user_id\",session.user.id).maybeSingle();const phoneValue=data?.phone&&typeof data.phone===\"object\"?`${data.phone.countryCode??\"\"} ${data.phone.phone??\"\"}`.trim():data?.phone??\"\";console.log(\"[RZ] fetchUserData complete\",{phoneValue,profileCompletePath,isMounted,pathname:window.location.pathname});if(profileCompletePath&&!phoneValue){const redirectTarget=getNormalizedRedirectTarget(profileCompletePath);const currentPath=`${window.location.pathname}${window.location.search}${window.location.hash}`;console.log(\"[RZ] redirect check\",{redirectTarget,currentPath});if(redirectTarget&&currentPath!==redirectTarget.comparable){if(redirectHandled)return;redirectHandled=true;console.log(\"[RZ] redirectToProfileComplete\",redirectTarget.href);const confirmed=window.confirm(profileCompleteMessage||\"회원가입이 아직 완료되지 않았어요.\\n연락처를 등록하셔야 모든 서비스를 이용하실 수 있어요.\\n\\n확인을 누르시면 입력 페이지로 바로 이동합니다.\");if(confirmed){window.location.replace(redirectTarget.href);}else{await supabase.auth.signOut();publishUserData(emptyUserData);}return;}}if(!isMounted)return;if(error){console.error(\"registrations select error:\",error.message);}publishUserData({isLoading:false,isLoggedIn:true,provider:session.user.app_metadata?.provider??\"\",name:data?.name??session.user.user_metadata?.full_name??session.user.user_metadata?.name??\"\",email:data?.email??session.user.email??\"\",phone:phoneValue,birthdate:data?.birthdate??\"\",gender:data?.gender??\"\",interests:data?.interests??[]});}const{data:{subscription}}=supabase.auth.onAuthStateChange((_event,session)=>{console.log(\"[RZ] onAuthStateChange\",_event,!!session,\"isMounted:\",isMounted);if(!isMounted)return;if(session){notifyAccountLinked(session);fetchUserDataWithSession(session);}else{publishUserData(emptyUserData);}});return()=>{isMounted=false;subscription.unsubscribe();};},[supabaseProjectId,supabaseAnonKey,tableName,profileCompletePath]);if(RenderTarget.current()===RenderTarget.canvas){return /*#__PURE__*/_jsx(\"div\",{style:{width:\"100%\",height:\"100%\",display:\"flex\",justifyContent:\"center\",alignItems:\"center\",backgroundColor:\"rgba(59, 130, 246, 0.08)\",color:\"#3b82f6\",fontSize:\"11px\",fontWeight:\"bold\",border:\"1px dashed #3b82f6\",borderRadius:\"8px\",whiteSpace:\"nowrap\",minWidth:\"max-content\",padding:\"0 12px\"},children:\"관제탑 (Provider)\"});}return /*#__PURE__*/_jsx(_Fragment,{});}addPropertyControls(ReZero_UserDataProvider,{supabaseProjectId:{type:ControlType.String,title:\"Project ID\",placeholder:\"your-project-id\"},supabaseAnonKey:{type:ControlType.String,title:\"Anon Key\"},tableName:{type:ControlType.String,title:\"테이블 이름\",defaultValue:\"registrations\"},profileCompletePath:{type:ControlType.Link,title:\"프로필 완성 페이지\",description:\"소셜 로그인 후 연락처 미등록 유저를 이 페이지로 이동시킵니다.\"},profileCompleteMessage:{type:ControlType.String,title:\"알림 메시지\",defaultValue:\"회원가입이 아직 완료되지 않았어요.\\n연락처를 등록하셔야 모든 서비스를 이용하실 수 있어요.\\n\\n확인을 누르시면 입력 페이지로 바로 이동합니다.\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ReZero_UserDataProvider\",\"slots\":[],\"annotations\":{\"framerDisableUnlink\":\"\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ReZero_UserDataProvider.map"],"mappings":"8PAAiW,SAAS,EAAgB,EAAS,CAAC,QAAQ,IAAI,uBAAuB,EAAS,WAAW,CAAC,EAAO,aAAa,EAAS,EAAO,cAAc,IAAI,YAAY,mBAAmB,CAAC,OAAO,EAAS,CAAC,CAAC,CAAE,SAAS,EAA4B,EAAK,CAAC,IAAM,EAAY,EAAK,MAAM,CAAC,GAAG,CAAC,EAAY,OAAO,KAAK,GAAG,CAAC,IAAM,EAAU,IAAI,IAAI,EAAY,EAAO,SAAS,OAA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