PageSourceSearch

https://www.zadikim.net/assets/AuthContext-CZ5TadfY.js

js zadikim.net collected 2026-10-02 14:19:12 UTC 4,105 bytes, 1 lines download raw bytes

1import{W as e,t,z as n}from"./jsx-runtime-AI795Xzu.js";import{n as r}from"./client-3BFQqWNj.js";var i=e(n()),a=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),o=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),s={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`},c=(0,i.forwardRef)(({color:e=`currentColor`,size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:a=``,children:c,iconNode:l,...u},d)=>(0,i.createElement)(`svg`,{ref:d,...s,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:o(`lucide`,a),...u},[...l.map(([e,t])=>(0,i.createElement)(e,t)),...Array.isArray(c)?c:[c]])),l=(e,t)=>{let n=(0,i.forwardRef)(({className:n,...r},s)=>(0,i.createElement)(c,{ref:s,iconNode:t,className:o(`lucide-${a(e)}`,n),...r}));return n.displayName=`${e}`,n},u=l(`LoaderCircle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),d=t(),f=(0,i.createContext)(void 0),p=1e4;function m({children:e}){let[t,n]=(0,i.useState)(null),[a,o]=(0,i.useState)(null),[s,c]=(0,i.useState)(null),[l,u]=(0,i.useState)(!1),[m,h]=(0,i.useState)(!0),[g,_]=(0,i.useState)(!1),v=(0,i.useRef)(0),y=(0,i.useRef)(null),b=(0,i.useCallback)(async e=>{if(!e){c(null),u(!1),_(!1);return}let t=++v.current;_(!0);let n=new AbortController,i=window.setTimeout(()=>n.abort(),p);try{let{data:i,error:a}=await r.from(`profiles`).select(`id, email, full_name, public_author_name, role, created_at, updated_at`).eq(`id`,e).maybeSingle().abortSignal(n.signal);if(t!==v.current)return;if(a){console.error(`Error fetching profile:`,a),c(null),u(!1);return}if(i){c(i);let{data:n,error:a}=await r.rpc(`is_admin_user`,{user_uuid:e});if(t!==v.current)return;a?(console.error(`Error checking admin access:`,a),u(i.role===`admin`||i.role===`moderator`)):u(!!n)}else console.error(`Authenticated user profile was not found`),c(null),u(!1)}catch(e){if(t!==v.current)return;console.error(`Exception fetching profile:`,e),c(null),u(!1)}finally{window.clearTimeout(i),t===v.current&&_(!1)}},[]);(0,i.useEffect)(()=>{let e=!0,t=window.setTimeout(()=>{e&&(console.warn(`Auth initialization timed out; clearing loading state`),h(!1))},12e3),{data:{subscription:i}}=r.auth.onAuthStateChange((t,r)=>{e&&(o(r),n(r?.user??null),r?.user||(v.current+=1,c(null),u(!1),_(!1)),h(!1))});return(async()=>{try{let{data:{session:t},error:i}=await r.auth.getSession();if(!e)return;if(i){console.error(`Error getting session:`,i),h(!1),o(null),n(null),c(null),u(!1),_(!1);return}o(t),n(t?.user??null),t?.user||(c(null),u(!1),_(!1)),h(!1)}catch(t){console.error(`Exception in getSession:`,t),e&&h(!1)}})(),()=>{e=!1,window.clearTimeout(t),i.unsubscribe()}},[]),(0,i.useEffect)(()=>{if(!m){if(!t?.id){y.current=null,c(null),u(!1),_(!1);return}y.current!==t.id&&(y.current=t.id,c(null),u(!1)),b(t.id)}},[m,t?.id,b]);let x=(0,i.useCallback)(async()=>{t?.id&&await b(t.id)},[t?.id,b]),S=(0,i.useCallback)(async()=>{try{let{error:e}=await r.auth.signOut();return localStorage.removeItem(`auth_profile`),Object.keys(localStorage).forEach(e=>{e.startsWith(`sb-`)&&localStorage.removeItem(e)}),Object.keys(sessionStorage).forEach(e=>{e.startsWith(`sb-`)&&sessionStorage.removeItem(e)}),v.current+=1,n(null),o(null),c(null),u(!1),_(!1),h(!1),{error:e}}catch(e){return console.error(`Error during sign out:`,e),v.current+=1,n(null),o(null),c(null),u(!1),_(!1),h(!1),{error:e}}},[]),C={user:t,session:a,profile:s,loading:m,profileLoading:g,isAdmin:l,signInWithMagicLink:(0,i.useCallback)(async e=>{let{error:t}=await r.auth.signInWithOtp({email:e,options:{emailRedirectTo:`${window.location.origin}/`}});return{error:t}},[]),signInWithGoogle:(0,i.useCallback)(async()=>r.auth.signInWithOAuth({provider:`google`,options:{redirectTo:`${window.location.origin}/`}}),[]),signOut:S,refreshProfile:x};return(0,d.jsx)(f.Provider,{value:C,children:e})}function h(){let e=(0,i.useContext)(f);if(e===void 0)throw Error(`useAuth must be used within an AuthProvider`);return e}export{l as i,h as n,u as r,m as t};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.