UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) 1.43 kB
import{createContext as o,useContext as e,useEffect as n}from"react";const r={login:{onComplete:[],onError:[]},logout:{onSuccess:[]},connectWallet:{onSuccess:[],onError:[]},connectOrCreateWallet:{onSuccess:[],onError:[]},createWallet:{onSuccess:[],onError:[]},linkAccount:{onSuccess:[],onError:[]},update:{onSuccess:[],onError:[]},configureMfa:{onMfaRequired:[]},setWalletPassword:{onSuccess:[],onError:[]},setWalletRecovery:{onSuccess:[],onError:[]},signMessage:{onSuccess:[],onError:[]},signTypedData:{onSuccess:[],onError:[]},sendTransaction:{onSuccess:[],onError:[]},signTransaction:{onSuccess:[],onError:[]},accessToken:{onAccessTokenGranted:[],onAccessTokenRemoved:[]},oAuthAuthorization:{onOAuthTokenGrant:[]},fundWallet:{onUserExited:[]},fundSolanaWallet:{onUserExited:[]},customAuth:{onAuthenticated:[],onUnauthenticated:[]}},t=/*#__PURE__*/o(void 0);let c=()=>e(t);function s(o,e){if(!e)return;let r=c().current[o];return n((()=>{for(let[n,t]of Object.entries(e))Object.prototype.hasOwnProperty.call(r,n)||console.warn(`Invalid event type "${n}" for action "${o}"`),r[n]?.push(t);return()=>{for(let[n,t]of Object.entries(e))Object.prototype.hasOwnProperty.call(r,n)||console.warn(`Invalid event type "${n}" for action "${o}"`),r[n]=r[n]?.filter((o=>o!==t))}}),[e])}function a(o,e,n,...r){for(let t of o.current[e][n])t(...r)}function u(){let o=c();return(e,n,...r)=>a(o,e,n,...r)}export{t as P,u as a,a as e,r as p,s as u};