import{useCallback as t}from"react";import{F as i}from"./frame-DtizlaLu.mjs";import{P as e}from"./errors-Dd6zfYtp.mjs";import{u as r}from"./internal-context-dfitw7Ot.mjs";import"./paths-BH8W4zMc.mjs";import"ofetch";const a=()=>{let{client:a,setAuthenticated:n,setUser:s}=r();return{initLoginToMiniApp:t((async()=>{let t=new i;if(!a)throw new e("Must initialize Privy client first.");return a.startAuthFlow(t),await t.init()}),[a]),loginToMiniApp:t((async({message:t,signature:r})=>{if(!a)throw new e("Must initialize Privy client first.");if(!(a.authFlow instanceof i))throw new e("Must initialize Farcaster Mini App flow first.");let o=(t=>{let i=t.match(/farcaster:\/\/fid\/(\d+)/);return i&&i[1]?parseInt(i[1],10):null})(t);if(!o)throw new e("Invalid message format; could not parse Farcaster ID.");a.authFlow.setAuthData({message:t,signature:r,fid:o});let{user:l}=await a.authenticate();return l&&(s(l),n(!0)),l}),[a,s,n])}};export{a as useLoginToMiniApp};
//# sourceMappingURL=farcaster.mjs.map
