PageSourceSearch

https://economypedia.com/assets/AuthContext-Y2GU_dyK.js

js economypedia.com collected 2026-10-09 23:28:04 UTC 1,714 bytes, 1 lines download raw bytes

1import{S as e,it as t,st as n}from"./router-compat-C8KrZUBs.js";import{n as r}from"./client-DBpB_GqA.js";var i=n(t(),1),a=e(),o=(0,i.createContext)(void 0),s=({children:e})=>{let[t,n]=(0,i.useState)(null),[s,c]=(0,i.useState)(null),[l,u]=(0,i.useState)(!0),[d,f]=(0,i.useState)(!0),[p,m]=(0,i.useState)(null),[h,g]=(0,i.useState)([]),[_,v]=(0,i.useState)(null),[y,b]=(0,i.useState)(!1),x=async e=>{f(!0),m(null);try{let[t,n]=await Promise.all([r.from(`user_roles`).select(`role`).eq(`user_id`,e),r.from(`profiles`).select(`display_name, avatar_url`).eq(`user_id`,e).maybeSingle()]);t.error?(g([]),m(t.error.message)):g(t.data?t.data.map(e=>e.role):[]),v(n.data??null)}finally{f(!1)}};(0,i.useEffect)(()=>{let e=null,{data:{subscription:t}}=r.auth.onAuthStateChange((t,r)=>{let i=r?.user?.id??null;c(r),n(r?.user??null),i!==e&&(e=i,r?.user?(f(!0),setTimeout(()=>x(r.user.id),0)):(g([]),m(null),v(null),f(!1))),u(!1)});return r.auth.getSession().then(({data:{session:t}})=>{e=t?.user?.id??null,c(t),n(t?.user??null),t?.user?x(t.user.id):f(!1),u(!1)}),()=>t.unsubscribe()},[]);let S=e=>h.includes(e),C=h.some(e=>[`admin`,`editor`,`writer`,`seo`].includes(e));return(0,a.jsx)(o.Provider,{value:{user:t,session:s,loading:l,rolesLoading:d,rolesError:p,roles:h,profile:_,hasRole:S,isStaff:C,signingOut:y,signOut:async()=>{b(!0);try{await r.auth.signOut()}finally{n(null),c(null),g([]),m(null),v(null),setTimeout(()=>b(!1),400)}},refreshProfile:async()=>{if(!t)return;let{data:e}=await r.from(`profiles`).select(`display_name, avatar_url`).eq(`user_id`,t.id).maybeSingle();v(e??null)}},children:e})},c=()=>{let e=(0,i.useContext)(o);if(!e)throw Error(`useAuth must be inside AuthProvider`);return e};export{c as n,s 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.