@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 7.38 kB
JavaScript
"use strict";var e=require("react/jsx-runtime"),r=require("@heroicons/react/24/outline/QuestionMarkCircleIcon"),i=require("@heroicons/react/24/outline/ShieldCheckIcon"),o=require("react"),t=require("./ModalHeader-C5Wuo3-1.js"),n=require("./useActiveWallet-BfMD5hzE.js"),s=require("./context-Cg3IEi80.js"),a=require("./privy-context-CrM9_s6G.js"),u=require("./EnrollTotp-RPco748Q.js"),l=require("./PinInput-B12fA7pp.js");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("styled-components"),require("@heroicons/react/24/outline/ArrowLeftIcon"),require("@heroicons/react/24/outline/ArrowRightIcon"),require("@heroicons/react/24/outline/XMarkIcon"),require("./internal-context-BJv4f_bO.js"),require("ofetch"),require("zustand"),require("react-device-detect"),require("./use-export-wallet-_EIyxyle.js"),require("./useWallets-dikDynAG.js"),require("viem"),require("@privy-io/js-sdk-core"),require("eventemitter3"),require("viem/utils"),require("./events-context-Di6--rDg.js"),require("tinycolor2"),require("@privy-io/are-addresses-equal"),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("@heroicons/react/24/outline/PhoneIcon"),require("./Chip-C6r7fZiR.js"),require("./LoadingSkeleton-BoyADunQ.js"),require("@heroicons/react/24/outline/ArrowRightEndOnRectangleIcon"),require("@heroicons/react/24/outline/ClockIcon"),require("./ErrorScreen-CL31INic.js"),require("lucide-react"),require("./index-DchMyzt9.js"),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-C-Rab7yP.js"),require("@scure/base"),require("@headlessui/react"),require("@walletconnect/ethereum-provider"),require("@privy-io/urls"),require("./PrivyPluginContext-DsgaS6n9.js"),require("./getEmbeddedConnectedWallet-pJd-l936.js"),require("js-cookie"),require("./frame-Oz7volks.js"),require("@privy-io/routes"),require("x402/client"),require("@privy-io/api-base"),require("viem/accounts"),require("./use-sign-with-user-signer-Cu_6Bx7m.js"),require("./reservoir-Bx0HQwbb.js"),require("./ScreenLayout-C4QHZMbl.js"),require("./Screen-DWnRbzSA.js"),require("./index-ByFhjjzH.js"),require("./LinkPasskeyScreen-D9Y8PpKL.js"),require("./TodoList-Cii_KrAk.js"),require("./CopyToClipboard-CC0DCGEH.js"),require("./Layouts-D3TOcPhm.js"),require("./Column-D8_5wTPp.js"),require("./LabelXs-C8rLnCfU.js"),require("./Subtitle-CR8zM7ZJ.js"),require("./Title-ifTy35V5.js"),require("./shared-DBm7PUrg.js"),require("@heroicons/react/24/solid/ShieldCheckIcon"),require("./QrCode-Bbg48Zky.js"),require("qrcode");var d=/*#__PURE__*/c(r),h=/*#__PURE__*/c(i);const q={component:()=>{let{user:r,ready:i}=a.usePrivyContext(),{data:c,onUserCloseViaDialogOrKeybindRef:q}=a.usePrivyModal(),j=s.useAppConfig(),[m,y]=o.useState(null),[p,f]=o.useState(null),[v,x]=o.useState(null),[g,M]=o.useState(!1),[k,C]=o.useState(!1),[S,w]=o.useState(),b=async()=>{S?I(S):r?await F({user:r}):I(Error("Must be logged in to manage MFA")),setTimeout((()=>{y(null),f(null)}),500)};if(q.current=b,!c?.mfaEnroll)throw Error("Missing modal data for MFA enrollment screen.");let{onFailure:I,onSuccess:F,onBack:P,mfaMethods:T,verify:A,generateTotpSecret:E,enrollTotp:L,unenrollTotp:R,enrollPasskey:B}=c.mfaEnroll,W=r?.mfaMethods.includes("sms"),H=r?.mfaMethods.includes("totp"),U=r?.mfaMethods.includes("passkey"),O=!!r?.phone,z=r?.linkedAccounts.filter((e=>"passkey"===e.type)).map((e=>e.credentialId))??[];function D(){y(null),f(null),w(void 0)}async function Q(e=z){try{w(void 0),C(!0);let r=await B(e);return await F({user:r})}catch(e){w(e)}finally{C(!1),M(!1)}}if(!i||!r||!j)/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(t.ModalHeader,{onClose:b,backFn:P},"header"),/*#__PURE__*/e.jsx(l.AppLogoContainer,{children:/*#__PURE__*/e.jsx(u.MfaShieldIcon,{})}),/*#__PURE__*/e.jsx(l.Container,{children:/*#__PURE__*/e.jsx(n.Loader,{})}),/*#__PURE__*/e.jsx(t.ModalFooter,{})]});if("sms"===m)return null;if("totp"===m)/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(t.ModalHeader,{backFn:D,onClose:b},"header"),/*#__PURE__*/e.jsx(l.IconWrapper,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/e.jsx(d.default,{})}),/*#__PURE__*/e.jsx(l.Title,{children:"Remove authenticator app verification?"}),/*#__PURE__*/e.jsxs(l.SubTitle,{children:["MFA adds an extra layer of security to your ",j?.name," account. Make sure you have other methods to secure your account."]}),/*#__PURE__*/e.jsx(l.BottomSection,{children:/*#__PURE__*/e.jsx(t.PrimaryButton,{$warn:!0,onClick:async function(){try{w(void 0),C(!0);let e=await R();return await F({user:e})}catch(e){w(e)}finally{C(!1),y(null)}},loading:k,children:"Remove"})}),/*#__PURE__*/e.jsx(t.ModalFooter,{})]});if("passkey"===m){let r=c.mfaEnroll.shouldUnlinkOnUnenrollMfa??!0;/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(t.ModalHeader,{backFn:D,onClose:b},"header"),/*#__PURE__*/e.jsx(l.IconWrapper,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/e.jsx(d.default,{})}),/*#__PURE__*/e.jsx(l.Title,{children:"Are you sure you want to remove this passkey?"}),/*#__PURE__*/e.jsx(l.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(l.BottomSection,{children:/*#__PURE__*/e.jsx(t.PrimaryButton,{$warn:!0,onClick:async function(){try{w(void 0),C(!0);let e=await B([]);return await F({user:e})}catch(e){w(e)}finally{C(!1),y(null)}},loading:k,children:"Remove"})}),/*#__PURE__*/e.jsx(t.ModalFooter,{})]})}return 0!==T.length||W||H||U?"sms"===p?null:"totp"===p&&v?/*#__PURE__*/e.jsx(u.EnrollTotp,{onClose:b,onReset:D,submitEnrollmentWithTotp:e=>async function(e){try{w(void 0),C(!0);let r=await L(e);return await F({user:r})}catch(e){w(e)}finally{C(!1),y(null)}}(e.mfaCode),error:S,totpInfo:{...v,appName:j?.name||"Privy"}}):"passkey"===p?/*#__PURE__*/e.jsx(u.EnrollPasskey,{onReset:D,onClose:b,submitEnrollmentWithPasskey:Q}):/*#__PURE__*/e.jsx(u.EnrollLandingScreen,{showIntro:!0,userMfaMethods:r.mfaMethods,appMfaMethods:j.mfa.methods,userHasAuthSms:O,backFn:P,handleSelectMethod:async function(e){w(void 0);try{await A()}catch(e){return void w(e)}return"totp"===e?(f(e),x(null),void E().then((({totpSecret:e,totpAuthUrl:r})=>{x({authUrl:r,secret:e})})).catch((()=>{x(null),D()}))):"passkey"===e&&1===z.length?await Q():void f(e)},isTotpLoading:"totp"===p&&!v,isPasskeyLoading:g,error:S,onClose:b,setRemovingMfaMethod:async function(e){w(void 0);try{await A()}catch(e){return void w(e)}y(e)}}):/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(t.ModalHeader,{onClose:b,backFn:P},"header"),/*#__PURE__*/e.jsx(l.IconWrapper,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/e.jsx(h.default,{})}),/*#__PURE__*/e.jsx(l.Title,{children:"Add more security"}),/*#__PURE__*/e.jsxs(l.SubTitle,{children:[j?.name," does not have any verification methods enabled."]}),/*#__PURE__*/e.jsx(l.BottomSection,{children:/*#__PURE__*/e.jsx(t.PrimaryButton,{onClick:b,children:"Close"})}),/*#__PURE__*/e.jsx(t.ModalFooter,{})]})}};exports.MfaAuthEnrollmentFlowScreen=q,exports.default=q;