@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 12.6 kB
JavaScript
"use strict";var e=require("react/jsx-runtime"),r=require("@heroicons/react/24/outline/QuestionMarkCircleIcon"),o=require("@heroicons/react/24/outline/ShieldCheckIcon"),n=require("@heroicons/react/24/solid/CheckBadgeIcon"),t=require("@heroicons/react/24/solid/IdentificationIcon"),i=require("react"),s=require("./Button-BEaVAnh4.js"),l=require("./useActiveWallet-B-Pd49hn.js"),a=require("./ModalHeader-n6Aqpos_.js"),c=require("./context-BPd2qxKv.js"),u=require("./internal-context-NWsAL807.js"),d=require("./get-is-unified-wallet-D6pn8A8g.js"),h=require("./index-Dz7affvL.js"),m=require("./EnrollTotp-CasC3VFI.js"),j=require("@heroicons/react/24/outline/CheckCircleIcon"),x=require("@heroicons/react/24/outline/PhoneIcon"),y=require("@privy-io/js-sdk-core"),f=require("./ConnectPhoneForm-C0SpJtis.js"),p=require("./PinInput-DSI6rjOn.js"),q=require("./ErrorScreen-BrKj88o9.js");function v(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("styled-components"),require("zustand"),require("react-device-detect"),require("./prepareFundingModalData-Do7d2fgq.js"),require("eventemitter3"),require("./events-context-Di6--rDg.js"),require("viem"),require("viem/utils"),require("./getPublicClient-CGlodIp_.js"),require("./useWallets-Bi_kf80t.js"),require("@heroicons/react/24/outline/ArrowLeftIcon"),require("@heroicons/react/24/outline/ArrowRightIcon"),require("@heroicons/react/24/outline/XMarkIcon"),require("tinycolor2"),require("ofetch"),require("uuid"),require("jose"),require("@coinbase/wallet-sdk"),require("@privy-io/ethereum"),require("mipd"),require("@privy-io/popup"),require("./paths-DizMb-lU.js"),require("./usePrivy-CANb3vg4.js"),require("@scure/base"),require("@headlessui/react"),require("@walletconnect/ethereum-provider"),require("@privy-io/urls"),require("js-cookie"),require("./frame-B14fp9oC.js"),require("@privy-io/routes"),require("x402/client"),require("@privy-io/api-base"),require("viem/accounts"),require("./use-sign-with-user-signer-BcAsQTGF.js"),require("./getEmbeddedConnectedWallet-6TsVZJkD.js"),require("@heroicons/react/24/outline/ChevronRightIcon"),require("@heroicons/react/24/outline/DevicePhoneMobileIcon"),require("@heroicons/react/24/outline/FingerPrintIcon"),require("@heroicons/react/24/outline/MinusCircleIcon"),require("./Chip-ChrHHazc.js"),require("./LoadingSkeleton-DoCrfGnl.js"),require("@heroicons/react/24/outline/ArrowRightEndOnRectangleIcon"),require("@heroicons/react/24/outline/ClockIcon"),require("./LinkPasskeyScreen-52yLU_Q-.js"),require("lucide-react"),require("./TodoList-Cm_a93ef.js"),require("./ScreenLayout-D6r13vU7.js"),require("./Screen-J7z62u7O.js"),require("./index-CRFXS9pP.js"),require("./CopyToClipboard-fd8Z3kQX.js"),require("./copy-BiZ7dtqy.js"),require("./Layouts-dRL0OSpp.js"),require("./Column-C2bAbJE0.js"),require("./LabelXs-CYMv6rOZ.js"),require("./Subtitle-Dtmrw8l5.js"),require("./Title-C-tHJvrb.js"),require("./shared-BPGwTh8c.js"),require("@heroicons/react/24/solid/ShieldCheckIcon"),require("./QrCode-D-MkB93C.js"),require("qrcode"),require("./reservoir-CQGyEBb7.js");var C=/*#__PURE__*/v(r),M=/*#__PURE__*/v(o),g=/*#__PURE__*/v(n),S=/*#__PURE__*/v(t),w=/*#__PURE__*/v(j),k=/*#__PURE__*/v(x);const b=({appName:r,onComplete:o,onReset:n,onClose:t})=>{let[l,u]=i.useState(""),[m,j]=i.useState(!1),[x,v]=i.useState(null),[C,M]=i.useState("enroll"),{initEnrollmentWithSms:g,submitEnrollmentWithSms:S}=h.useMfaEnrollment(),{data:b}=d.usePrivyModal(),F=c.useAppConfig();function I(){b?.mfaEnrollmentFlow?.onSuccess(),o()}return x?/*#__PURE__*/e.jsx(q.ErrorScreenView,{allowlistConfig:F.allowlistConfig,error:x,onBack:()=>v(null),onRetry:()=>v(null)}):"enroll"===C?/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(a.ModalHeader,{backFn:n,onClose:t},"header"),/*#__PURE__*/e.jsx(p.IconWrapper,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/e.jsx(k.default,{})}),/*#__PURE__*/e.jsx(p.Title,{children:"Set up SMS verification"}),/*#__PURE__*/e.jsxs(p.SubTitle,{children:["We'll text a verification code to this mobile device whenever you use your ",r," ","wallet."]}),/*#__PURE__*/e.jsxs(p.Container,{children:[/*#__PURE__*/e.jsx(f.ConnectPhoneNumberForm,{onSubmit:async function({qualifiedPhoneNumber:e}){try{await g({phoneNumber:e}),u(e),M("verify")}catch(e){v(e)}},hideRecent:!0}),/*#__PURE__*/e.jsxs(p.TermsText,{children:["By providing your mobile number, you agree to receive text messages from ",F?.name,". Some carrier charges may apply"]})]}),/*#__PURE__*/e.jsx(a.ModalFooter,{})]}):m?/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(a.ModalHeader,{onClose:I},"header"),/*#__PURE__*/e.jsx(p.IconWrapper,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/e.jsx(w.default,{})}),/*#__PURE__*/e.jsx(p.Title,{children:"SMS verification added"}),/*#__PURE__*/e.jsxs(p.SubTitle,{children:["From now on, you'll enter the verification code sent to your mobile device whenever you use your ",r," wallet."]}),/*#__PURE__*/e.jsx(p.BottomSection,{children:/*#__PURE__*/e.jsx(s.PrimaryButton,{onClick:I,children:"Done"})}),/*#__PURE__*/e.jsx(a.ModalFooter,{})]}):/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(a.ModalHeader,{backFn:function(){"verify"===C?M("enroll"):n()},onClose:t},"header"),/*#__PURE__*/e.jsx(p.IconWrapper,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/e.jsx(k.default,{})}),/*#__PURE__*/e.jsx(p.Title,{children:"Enter enrollment code"}),/*#__PURE__*/e.jsxs(p.Container,{children:[/*#__PURE__*/e.jsx(p.NumericPinInput,{onChange:async function(e){try{if(!e)return;await S({phoneNumber:l,mfaCode:e}),j(!0)}catch(e){if(h.errorIndicatesMfaRateLimit(e))throw Error("You have exceeded the maximum number of attempts. Please close this window and try again in 10 seconds.");if(h.errorIndicatesMfaVerificationFailed(e))throw Error("The code you entered is not valid");if(h.errorIndicatesMfaTimeout(e))throw Error("You have exceeded the time limit for code entry. Please try again in 30 seconds.");throw h.errorIndicatesMfaCanceled(e)?Error("Verification canceled"):Error("Unknown error")}}}),/*#__PURE__*/e.jsxs(p.SubTitle,{children:["To continue, enter the 6-digit code sent to ",/*#__PURE__*/e.jsx("strong",{children:y.lastFourDigits(l)})]})]}),/*#__PURE__*/e.jsx(a.ModalFooter,{})]})},F={component:()=>{let{user:r,enrollInMfa:o,ready:n}=d.usePrivyContext(),[t,j]=i.useState(null),{unenrollWithSms:x,unenrollWithTotp:y,unenrollWithPasskey:f,submitEnrollmentWithTotp:q,initEnrollmentWithPasskey:v,submitEnrollmentWithPasskey:w,initEnrollmentWithTotp:k}=h.useMfaEnrollment(),{data:F,onUserCloseViaDialogOrKeybindRef:I}=d.usePrivyModal(),E=c.useAppConfig(),{closePrivyModal:T}=u.usePrivyInternal(),{promptMfa:P}=h.useMfa(),[B,W]=i.useState(!1),[L,R]=i.useState(null),[A,H]=i.useState(null),N=()=>{T({shouldCallAuthOnSuccess:!0}),o(!1),setTimeout((()=>{j(null),R(null)}),500)},[U,D]=i.useState(!1),[O,V]=i.useState();I.current=N;let Y=r?.mfaMethods.includes("sms"),$=!!r?.phone,K=r?.mfaMethods.includes("totp"),Q=r?.mfaMethods.includes("passkey"),X=Y||K||Q,z=r?.linkedAccounts.filter((e=>"passkey"===e.type)).map((e=>e.credentialId))??[];function G(){j(null),R(null)}async function J(e=z){D(!0);try{return await v(),await w({credentialIds:e},{removeForLogin:F?.mfaEnrollmentFlow?.shouldUnlinkOnUnenrollMfa}),F?.mfaEnrollmentFlow?.onSuccess(),N()}catch(e){V(e)}finally{D(!1)}}if(i.useEffect((()=>{X&&W(!0)}),[X]),!n||!r||!E/*#__PURE__*/)return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(a.ModalHeader,{onClose:N},"header"),/*#__PURE__*/e.jsx(p.AppLogoContainer,{children:/*#__PURE__*/e.jsx(m.MfaShieldIcon,{})}),/*#__PURE__*/e.jsx(p.Container,{children:/*#__PURE__*/e.jsx(l.Loader,{})}),/*#__PURE__*/e.jsx(a.ModalFooter,{})]});if("sms"===t)/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(a.ModalHeader,{backFn:G,onClose:N},"header"),/*#__PURE__*/e.jsx(p.IconWrapper,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/e.jsx(C.default,{})}),/*#__PURE__*/e.jsx(p.Title,{children:"Remove SMS verification?"}),/*#__PURE__*/e.jsxs(p.SubTitle,{children:["MFA adds an extra layer of security to your ",E?.name," account. Make sure you have other methods to secure your account."]}),/*#__PURE__*/e.jsx(p.BottomSection,{children:/*#__PURE__*/e.jsx(s.PrimaryButton,{$warn:!0,onClick:async function(){j(null);try{await x()}catch(e){j(null)}},children:"Remove"})}),/*#__PURE__*/e.jsx(a.ModalFooter,{})]});if("totp"===t)/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(a.ModalHeader,{backFn:G,onClose:N},"header"),/*#__PURE__*/e.jsx(p.IconWrapper,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/e.jsx(C.default,{})}),/*#__PURE__*/e.jsx(p.Title,{children:"Remove authenticator app verification?"}),/*#__PURE__*/e.jsxs(p.SubTitle,{children:["MFA adds an extra layer of security to your ",E?.name," account. Make sure you have other methods to secure your account."]}),/*#__PURE__*/e.jsx(p.BottomSection,{children:/*#__PURE__*/e.jsx(s.PrimaryButton,{$warn:!0,onClick:async function(){j(null);try{await y()}catch(e){j(null)}},children:"Remove"})}),/*#__PURE__*/e.jsx(a.ModalFooter,{})]});if("passkey"===t){let r=F?.mfaEnrollmentFlow?.shouldUnlinkOnUnenrollMfa??!0;/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(a.ModalHeader,{backFn:G,onClose:N},"header"),/*#__PURE__*/e.jsx(p.IconWrapper,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/e.jsx(C.default,{})}),/*#__PURE__*/e.jsx(p.Title,{children:"Are you sure you want to remove this passkey?"}),/*#__PURE__*/e.jsx(p.SubTitle,{children:r?"Removing your passkey will remove as both a verification method and a login method.":"Removing your passkey will remove as a verification method."}),/*#__PURE__*/e.jsx(p.BottomSection,{children:/*#__PURE__*/e.jsx(s.PrimaryButton,{$warn:!0,onClick:async function(){j(null);try{await f({removeForLogin:F?.mfaEnrollmentFlow?.shouldUnlinkOnUnenrollMfa})}catch(e){j(null)}},children:"Remove"})}),/*#__PURE__*/e.jsx(a.ModalFooter,{})]})}if(0===F.mfaEnrollmentFlow.mfaMethods.length&&!X)/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(a.ModalHeader,{onClose:N},"header"),/*#__PURE__*/e.jsx(p.IconWrapper,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/e.jsx(M.default,{})}),/*#__PURE__*/e.jsx(p.Title,{children:"Add more security"}),/*#__PURE__*/e.jsxs(p.SubTitle,{children:[E?.name," does not have any verification methods enabled."]}),/*#__PURE__*/e.jsx(p.BottomSection,{children:/*#__PURE__*/e.jsx(s.PrimaryButton,{onClick:N,children:"Close"})}),/*#__PURE__*/e.jsx(a.ModalFooter,{})]});let Z=!X&&!B;return Z?/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(a.ModalHeader,{onClose:N},"header"),/*#__PURE__*/e.jsx(p.IconWrapper,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/e.jsx(M.default,{})}),/*#__PURE__*/e.jsx(p.Title,{children:"Transaction Protection"}),/*#__PURE__*/e.jsx(p.SubTitle,{children:"Set up transaction protection to add an extra layer of security to your account"}),/*#__PURE__*/e.jsxs(p.List,{children:[/*#__PURE__*/e.jsxs(p.ListItem,{children:[/*#__PURE__*/e.jsx(p.ListItemIcon,{children:/*#__PURE__*/e.jsx(g.default,{})}),"Enable 2-Step verification for your ",E?.name," wallet."]}),/*#__PURE__*/e.jsxs(p.ListItem,{children:[/*#__PURE__*/e.jsx(p.ListItemIcon,{children:/*#__PURE__*/e.jsx(S.default,{})}),"You'll be prompted to authenticate to complete transactions."]})]}),/*#__PURE__*/e.jsxs(p.BottomSection,{children:[/*#__PURE__*/e.jsx(s.PrimaryButton,{onClick:()=>W(!0),children:"Continue"}),/*#__PURE__*/e.jsx(s.SecondaryButton,{onClick:N,children:"Not now"})]}),/*#__PURE__*/e.jsx(a.ModalFooter,{})]}):"sms"===L?/*#__PURE__*/e.jsx(b,{appName:E?.name||"Privy",onComplete:N,onReset:G,onClose:N}):"totp"===L&&A?/*#__PURE__*/e.jsx(m.EnrollTotp,{onClose:N,onReset:G,submitEnrollmentWithTotp:({mfaCode:e})=>async function(e){try{return V(void 0),await q({mfaCode:e}),F?.mfaEnrollmentFlow?.onSuccess(),N()}catch(e){V(e)}finally{j(null)}}(e),totpInfo:{...A,appName:E?.name||"Privy"}}):"passkey"===L?/*#__PURE__*/e.jsx(m.EnrollPasskey,{onReset:G,onClose:N,submitEnrollmentWithPasskey:J}):/*#__PURE__*/e.jsx(m.EnrollLandingScreen,{showIntro:Z,userMfaMethods:r.mfaMethods,appMfaMethods:E.mfa.methods,userHasAuthSms:$,backFn:function(){W(!1)},handleSelectMethod:async function(e){try{await P()}catch(e){return void V(e)}return"totp"===e?(R(e),H(null),void k().then((e=>{H(e)})).catch((()=>{H(null),G()}))):"passkey"===e&&1===z.length?await J():void R(e)},isTotpLoading:"totp"===L&&!A,isPasskeyLoading:U,error:O,onClose:N,setRemovingMfaMethod:async e=>{try{await P()}catch(e){return void V(e)}j(e)}})}};exports.MfaEnrollmentFlowScreen=F,exports.default=F;