UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) 10 kB
"use strict";var t,e=require("ofetch"),s=require("react");class a extends Error{toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}constructor(t,e,s){super(t),e instanceof Error&&(this.cause=e),this.privyErrorCode=s}}class i extends a{constructor(t,e,s,a,i,r){super(s,a,i),this.type=t,this.status=e,this.data=r}}class r extends a{constructor(t,e,s){super(t,e,s),this.type="client_error"}}const n=t=>t instanceof a?t:t instanceof Error?new r(t.message,t):new r(`Internal error: ${t}`);var o=((t={}).OAUTH_ACCOUNT_SUSPENDED="oauth_account_suspended",t.MISSING_OR_INVALID_PRIVY_APP_ID="missing_or_invalid_privy_app_id",t.MISSING_OR_INVALID_PRIVY_ACCOUNT_ID="missing_or_invalid_privy_account_id",t.MISSING_OR_INVALID_TOKEN="missing_or_invalid_token",t.INVALID_DATA="invalid_data",t.INVALID_CAPTCHA="invalid_captcha",t.LINKED_TO_ANOTHER_USER="linked_to_another_user",t.CANNOT_LINK_MORE_OF_TYPE="cannot_link_more_of_type",t.FAILED_TO_LINK_ACCOUNT="failed_to_link_account",t.FAILED_TO_UPDATE_ACCOUNT="failed_to_update_account",t.USER_EXITED_UPDATE_FLOW="exited_update_flow",t.ALLOWLIST_REJECTED="allowlist_rejected",t.OAUTH_USER_DENIED="oauth_user_denied",t.OAUTH_UNEXPECTED="oauth_unexpected",t.UNKNOWN_AUTH_ERROR="unknown_auth_error",t.USER_EXITED_AUTH_FLOW="exited_auth_flow",t.USER_EXITED_LINK_FLOW="exited_link_flow",t.USER_EXITED_SET_PASSWORD_FLOW="user_exited_set_password_flow",t.MUST_BE_AUTHENTICATED="must_be_authenticated",t.UNKNOWN_CONNECT_WALLET_ERROR="unknown_connect_wallet_error",t.GENERIC_CONNECT_WALLET_ERROR="generic_connect_wallet_error",t.CLIENT_REQUEST_TIMEOUT="client_request_timeout",t.INVALID_CREDENTIALS="invalid_credentials",t.MISSING_MFA_CREDENTIALS="missing_or_invalid_mfa",t.UNKNOWN_MFA_ERROR="unknown_mfa_error",t.EMBEDDED_WALLET_ALREADY_EXISTS="embedded_wallet_already_exists",t.EMBEDDED_WALLET_NOT_FOUND="embedded_wallet_not_found",t.EMBEDDED_WALLET_CREATE_ERROR="embedded_wallet_create_error",t.UNKNOWN_EMBEDDED_WALLET_ERROR="unknown_embedded_wallet_error",t.EMBEDDED_WALLET_PASSWORD_UNCONFIRMED="embedded_wallet_password_unconfirmed",t.EMBEDDED_WALLET_PASSWORD_ALREADY_EXISTS="embedded_wallet_password_already_exists",t.EMBEDDED_WALLET_RECOVERY_ALREADY_EXISTS="embedded_wallet_recovery_already_exists",t.TRANSACTION_FAILURE="transaction_failure",t.UNSUPPORTED_CHAIN_ID="unsupported_chain_id",t.NOT_SUPPORTED="not_supported",t.CAPTCHA_TIMEOUT="captcha_timeout",t.INVALID_MESSAGE="invalid_message",t.UNABLE_TO_SIGN="unable_to_sign",t.CAPTCHA_FAILURE="captcha_failure",t.CAPTCHA_DISABLED="captcha_disabled",t.SESSION_STORAGE_UNAVAILABLE="session_storage_unavailable",t.TOO_MANY_REQUESTS="too_many_requests",t.USER_LIMIT_REACHED="max_accounts_reached",t.DISALLOWED_LOGIN_METHOD="disallowed_login_method",t.DISALLOWED_PLUS_EMAIL="disallowed_plus_email",t.PASSKEY_NOT_ALLOWED="passkey_not_allowed",t.USER_DOES_NOT_EXIST="user_does_not_exist",t.INSUFFICIENT_BALANCE="insufficient_balance",t.ACCOUNT_TRANSFER_REQUIRED="account_transfer_required",t.BUFFER_NOT_DEFINED="buffer_not_defined",t);const p=()=>{throw Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")},l=/*#__PURE__*/s.createContext({setAuthenticated:p,setUser:p,setIsNewUser:p,isNewUserThisSession:!1,walletConnectionStatus:null,connectors:[],solanaWallets:[],rpcConfig:{rpcUrls:{}},showFiatPrices:!0,chains:[],clientAnalyticsId:null,pendingTransaction:null,client:null,privy:null,appId:"notAdded",onCustomAuthAuthenticated:p,hideWalletUIs:{current:!1},nativeTokenSymbolForChainId:p,initializeWalletProxy:p,getAuthMeta:p,getAuthFlow:p,closePrivyModal:p,openPrivyModal:p,connectWallet:p,initLoginWithWallet:p,loginWithWallet:p,initLoginWithFarcaster:p,loginWithFarcaster:p,loginWithCode:p,initLoginWithEmail:p,initLoginWithSms:p,initUpdateEmail:p,initUpdatePhone:p,resendEmailCode:p,resendSmsCode:p,initLoginWithHeadlessOAuth:p,loginWithHeadlessOAuth:p,crossAppAuthFlow:p,initLoginWithOAuth:p,loginWithOAuth:p,passkeyAuthState:{status:"initial"},setPasskeyAuthState:p,initSignupWithPasskey:p,signupWithPasskey:p,initLoginWithPasskey:p,loginWithPasskey:p,initLinkWithPasskey:p,linkWithPasskey:p,refreshSessionAndUser:p,walletProxy:null,createAnalyticsEvent:p,acceptTerms:p,getUsdTokenPrice:p,getUsdPriceForSol:p,getSplTokenMetadata:p,recoverPrimaryWallet:p,updateWallets:p,fundWallet:p,openModal:p,setReadyToTrue:p,requestFarcasterSignerStatus:p,initLoginWithTelegram:p,loginWithTelegram:p,generateSiweMessage:p,generateSiweMessageForSmartWallet:p,linkWithSiwe:p,linkSmartWallet:p,delegateWallet:p,revokeDelegatedWallets:p,exportSolanaWallet:p,connectCoinbaseSmartWallet:p,initiateAccountTransfer:p,emailOtpState:{status:"initial"},setEmailOtpState:p,smsOtpState:{status:"initial"},setSmsOtpState:p,siweState:{status:"initial"},setSiweState:p,oAuthState:{status:"initial"},setOAuthState:p,telegramAuthState:{status:"initial"},setTelegramAuthState:p,isHeadlessOAuthLoading:!1,isHeadlessSigning:p});exports.InternalPrivyContext=l,exports.PrivyApiError=i,exports.PrivyClientError=r,exports.PrivyConnectorError=class extends a{constructor(t,e,s){super(t,e,s),this.type="connector_error"}},exports.PrivyEmbeddedWalletError=class extends r{constructor(t="Embedded wallet error",e){super(t,e,"unknown_embedded_wallet_error")}},exports.PrivyError=a,exports.PrivyErrorCode=o,exports.PrivyNotReadyError=class extends r{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},exports.PrivyTimeoutError=class extends r{constructor(){super("Request timed out",void 0,"client_request_timeout")}},exports.PrivyUnauthenticatedError=class extends r{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}},exports.PrivyUserLimitReachedError=class extends r{constructor(t){super("This application is in development mode and must be upgraded to production to log in new users.",t,"max_accounts_reached")}},exports.acceptTermsPath="/api/v1/users/me/accept_terms",exports.analyticsEventsPath="/api/v1/analytics_events",exports.authenticateFarcasterV2Path="api/v2/farcaster/authenticate",exports.coinbaseOnRampInitPath="/api/v1/funding/coinbase_on_ramp/init",exports.coinbaseOnRampStatusPath="/api/v1/funding/coinbase_on_ramp/status",exports.customJwtAccountAuthenticatePath="/api/v1/custom_jwt_account/authenticate",exports.delegatedActionsRevokePath="/api/v1/wallets/revoke",exports.farcasterAuthenticatePath="/api/v1/farcaster/authenticate",exports.farcasterInitPath="/api/v1/farcaster/init",exports.farcasterLinkPath="/api/v1/farcaster/link",exports.farcasterStatusPath="/api/v1/farcaster/status",exports.formatApiError=t=>{if(t instanceof a)return t;if(!(t instanceof e.FetchError))return n(t);if(!t.response)return new i("api_error",null,t.message,t);let{type:s,message:r,error:o,code:p}=t.data;return new i(s||"ApiError",t.response.status,r||o,t,p,t.data)},exports.formatPrivyError=n,exports.guestAccountAuthenticatePath="/api/v1/guest/authenticate",exports.initFarcasterV2Path="api/v2/farcaster/init",exports.mfaPasskeyInitPath="/api/v1/mfa/passkeys/init",exports.mfaPasswordlessSmsInitPath="/api/v1/mfa/passwordless_sms/init",exports.moonpayPluginOnRampPath="/api/v1/plugins/moonpay_on_ramp/sign",exports.notImplemented=p,exports.notImplementedWithMessage=t=>()=>{throw Error(t.trim())},exports.oAuthAuthenticatePath="/api/v1/oauth/authenticate",exports.oAuthInitPath="/api/v1/oauth/init",exports.oAuthLinkPath="/api/v1/oauth/link",exports.passkeyAuthenticatePath="/api/v1/passkeys/authenticate",exports.passkeyInitAuthenticatePath="/api/v1/passkeys/authenticate/init",exports.passkeyInitLinkPath="/api/v1/passkeys/link/init",exports.passkeyInitRegisterPath="/api/v1/passkeys/register/init",exports.passkeyLinkPath="/api/v1/passkeys/link",exports.passkeyRegisterPath="/api/v1/passkeys/register",exports.passwordlessAuthenticatePath="/api/v1/passwordless/authenticate",exports.passwordlessInitPath="/api/v1/passwordless/init",exports.passwordlessLinkPath="/api/v1/passwordless/link",exports.passwordlessSmsAuthenticatePath="/api/v1/passwordless_sms/authenticate",exports.passwordlessSmsInitPath="/api/v1/passwordless_sms/init",exports.passwordlessSmsLinkPath="/api/v1/passwordless_sms/link",exports.recoveryOAuthAuthenticatePath="/api/v1/recovery/oauth/authenticate",exports.recoveryOAuthInitICloudPath="/api/v1/recovery/oauth/init_icloud",exports.recoveryOAuthInitPath="/api/v1/recovery/oauth/init",exports.sessionsLogoutPath="/api/v1/sessions/logout",exports.sessionsRefreshPath="/api/v1/sessions",exports.siweAuthenticatePath="/api/v1/siwe/authenticate",exports.siweInitPath="/api/v1/siwe/init",exports.siweLinkPath="/api/v1/siwe/link",exports.siwsAuthenticatePath="/api/v1/siws/authenticate",exports.siwsInitPath="/api/v1/siws/init",exports.siwsLinkPath="/api/v1/siws/link",exports.siwsUnlinkWalletPath="/api/v1/siws/unlink",exports.smartWalletLinkPath="/api/v1/siwe/link_smart_wallet",exports.telegramAccountAuthenticatePath="/api/v1/telegram/authenticate",exports.telegramAccountLinkPath="/api/v1/telegram/link",exports.telegramAccountTransferPath="/api/v1/telegram/transfer",exports.telegramAccountUnlinkPath="/api/v1/telegram/unlink",exports.transactionScanningPath="/api/v1/scan/transaction",exports.transferEmailPath="/api/v1/passwordless/transfer",exports.transferFarcasterPath="/api/v1/farcaster/transfer",exports.transferOAuthPath="/api/v1/oauth/transfer",exports.transferPhonePath="/api/v1/passwordless_sms/transfer",exports.transferWalletPath="/api/v1/siwe/transfer",exports.unlinkEmailPath="/api/v1/passwordless/unlink",exports.unlinkFarcasterPath="/api/v1/farcaster/unlink",exports.unlinkOAuthPath="/api/v1/oauth/unlink",exports.unlinkPhonePath="/api/v1/passwordless_sms/unlink",exports.unlinkWalletPath="/api/v1/siwe/unlink",exports.updateEmailPath="/api/v1/passwordless/update",exports.updatePhonePath="/api/v1/passwordless_sms/update",exports.usePrivyInternal=()=>s.useContext(l),exports.usersMePath="/api/v1/users/me";