@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 6.52 kB
JavaScript
import{FetchError as e}from"ofetch";import{useContext as t,createContext as s}from"react";var a;class i extends Error{toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}constructor(e,t,s){super(e),t instanceof Error&&(this.cause=t),this.privyErrorCode=s}}class n extends i{constructor(e,t,s,a,i,n){super(s,a,i),this.type=e,this.status=t,this.data=n}}class _ extends i{constructor(e,t,s){super(e,t,s),this.type="client_error"}}class r extends _{constructor(){super("Request timed out",void 0,"client_request_timeout")}}class o extends i{constructor(e,t,s){super(e,t,s),this.type="connector_error"}}const l=t=>{if(t instanceof i)return t;if(!(t instanceof e))return d(t);if(!t.response)return new n("api_error",null,t.message,t);let{type:s,message:a,error:_,code:r}=t.data;return new n(s||"ApiError",t.response.status,a||_,t,r,t.data)},d=e=>e instanceof i?e:e instanceof Error?new _(e.message,e):new _(`Internal error: ${e}`);var u=((a={}).OAUTH_ACCOUNT_SUSPENDED="oauth_account_suspended",a.MISSING_OR_INVALID_PRIVY_APP_ID="missing_or_invalid_privy_app_id",a.MISSING_OR_INVALID_PRIVY_ACCOUNT_ID="missing_or_invalid_privy_account_id",a.MISSING_OR_INVALID_TOKEN="missing_or_invalid_token",a.INVALID_DATA="invalid_data",a.INVALID_CAPTCHA="invalid_captcha",a.LINKED_TO_ANOTHER_USER="linked_to_another_user",a.CANNOT_LINK_MORE_OF_TYPE="cannot_link_more_of_type",a.FAILED_TO_LINK_ACCOUNT="failed_to_link_account",a.FAILED_TO_UPDATE_ACCOUNT="failed_to_update_account",a.USER_EXITED_UPDATE_FLOW="exited_update_flow",a.ALLOWLIST_REJECTED="allowlist_rejected",a.OAUTH_USER_DENIED="oauth_user_denied",a.OAUTH_UNEXPECTED="oauth_unexpected",a.UNKNOWN_AUTH_ERROR="unknown_auth_error",a.USER_EXITED_AUTH_FLOW="exited_auth_flow",a.USER_EXITED_LINK_FLOW="exited_link_flow",a.USER_EXITED_SET_PASSWORD_FLOW="user_exited_set_password_flow",a.MUST_BE_AUTHENTICATED="must_be_authenticated",a.UNKNOWN_CONNECT_WALLET_ERROR="unknown_connect_wallet_error",a.GENERIC_CONNECT_WALLET_ERROR="generic_connect_wallet_error",a.CLIENT_REQUEST_TIMEOUT="client_request_timeout",a.INVALID_CREDENTIALS="invalid_credentials",a.MISSING_MFA_CREDENTIALS="missing_or_invalid_mfa",a.UNKNOWN_MFA_ERROR="unknown_mfa_error",a.EMBEDDED_WALLET_ALREADY_EXISTS="embedded_wallet_already_exists",a.EMBEDDED_WALLET_NOT_FOUND="embedded_wallet_not_found",a.EMBEDDED_WALLET_CREATE_ERROR="embedded_wallet_create_error",a.UNKNOWN_EMBEDDED_WALLET_ERROR="unknown_embedded_wallet_error",a.EMBEDDED_WALLET_PASSWORD_UNCONFIRMED="embedded_wallet_password_unconfirmed",a.EMBEDDED_WALLET_PASSWORD_ALREADY_EXISTS="embedded_wallet_password_already_exists",a.EMBEDDED_WALLET_RECOVERY_ALREADY_EXISTS="embedded_wallet_recovery_already_exists",a.TRANSACTION_FAILURE="transaction_failure",a.UNSUPPORTED_CHAIN_ID="unsupported_chain_id",a.NOT_SUPPORTED="not_supported",a.CAPTCHA_TIMEOUT="captcha_timeout",a.INVALID_MESSAGE="invalid_message",a.UNABLE_TO_SIGN="unable_to_sign",a.CAPTCHA_FAILURE="captcha_failure",a.CAPTCHA_DISABLED="captcha_disabled",a.SESSION_STORAGE_UNAVAILABLE="session_storage_unavailable",a.TOO_MANY_REQUESTS="too_many_requests",a.USER_LIMIT_REACHED="max_accounts_reached",a.DISALLOWED_LOGIN_METHOD="disallowed_login_method",a.DISALLOWED_PLUS_EMAIL="disallowed_plus_email",a.PASSKEY_NOT_ALLOWED="passkey_not_allowed",a.USER_DOES_NOT_EXIST="user_does_not_exist",a.INSUFFICIENT_BALANCE="insufficient_balance",a.ACCOUNT_TRANSFER_REQUIRED="account_transfer_required",a.BUFFER_NOT_DEFINED="buffer_not_defined",a.UNSUPPORTED_WALLET_TYPE="unsupported_wallet_type",a.NO_SOLANA_ACCOUNTS="no_solana_accounts",a.UNKNOWN_FUNDING_ERROR="unknown_funding_error",a);class E extends _{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}}class c extends _{constructor(e="Embedded wallet error",t){super(e,t,"unknown_embedded_wallet_error")}}class A extends _{constructor(e="User must be authenticated"){super(e,void 0,"must_be_authenticated")}}class S extends _{constructor(e){super("This application is in development mode and must be upgraded to production to log in new users.",e,"max_accounts_reached")}}class T extends o{constructor(){super("No Solana accounts found in wallet",void 0,"no_solana_accounts")}}const h=()=>{throw Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")},N=e=>()=>{throw Error(e.trim())},p=()=>{},O=/*#__PURE__*/s({setAuthenticated:h,setUser:h,setIsNewUser:h,isNewUserThisSession:!1,walletConnectionStatus:null,setWalletConnectionStatus:h,connectors:[],rpcConfig:{rpcUrls:{}},showFiatPrices:!0,chains:[],clientAnalyticsId:null,pendingTransaction:null,client:null,privy:null,appId:"notAdded",onCustomAuthAuthenticated:h,hideWalletUIs:{current:!1},nativeTokenSymbolForChainId:h,initializeWalletProxy:h,getAuthMeta:h,getAuthFlow:h,closePrivyModal:h,openPrivyModal:h,connectWallet:h,initLoginWithWallet:h,loginWithWallet:h,initLoginWithFarcaster:h,loginWithFarcaster:h,loginWithCode:h,initLoginWithEmail:h,initLoginWithSms:h,initUpdateEmail:h,initUpdatePhone:h,resendEmailCode:h,resendSmsCode:h,initLoginWithHeadlessOAuth:h,loginWithHeadlessOAuth:h,crossAppAuthFlow:h,initLoginWithOAuth:h,loginWithOAuth:h,passkeyAuthState:{status:"initial"},setPasskeyAuthState:h,initSignupWithPasskey:h,signupWithPasskey:h,initLoginWithPasskey:h,loginWithPasskey:h,initLinkWithPasskey:h,linkWithPasskey:h,refreshSessionAndUser:h,walletProxy:null,createAnalyticsEvent:h,acceptTerms:h,getUsdTokenPrice:h,getUsdPriceForSol:h,getSplTokenMetadata:h,recoverEmbeddedWallet:h,updateWallets:h,fundWallet:h,openModal:h,setReadyToTrue:h,requestFarcasterSignerStatus:h,initLoginWithTelegram:h,loginWithTelegram:h,generateSiweMessage:h,generateSiweMessageForSmartWallet:h,loginWithSiwe:h,linkWithSiwe:h,linkSmartWallet:h,delegateWallet:h,revokeDelegatedWallets:h,connectCoinbaseSmartWallet:h,connectBaseAccount:h,initiateAccountTransfer:h,emailOtpState:{status:"initial"},setEmailOtpState:h,smsOtpState:{status:"initial"},setSmsOtpState:h,siweState:{status:"initial"},setSiweState:h,oAuthState:{status:"initial"},setOAuthState:h,telegramAuthState:{status:"initial"},setTelegramAuthState:h,isHeadlessOAuthLoading:!1,isHeadlessSigning:h,inProgressAuthFlowRef:{current:null},inProgressLoginOrLinkMethodRef:{current:null},baseAccountSdk:void 0,setBaseAccountSdk:h}),I=()=>t(O);export{O as I,o as P,_ as a,u as b,i as c,p as d,n as e,l as f,E as g,r as h,d as i,T as j,S as k,N as l,c as m,h as n,A as o,I as u};