@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 6.6 kB
JavaScript
import{jsxs as e,Fragment as o,jsx as t}from"react/jsx-runtime";import r from"@heroicons/react/24/outline/QuestionMarkCircleIcon";import i from"@heroicons/react/24/outline/ShieldCheckIcon";import{useState as n}from"react";import{M as s,b as a,P as m}from"./ModalHeader-BnVmXtvG.mjs";import{L as l}from"./useActiveWallet-CvP7iYvj.mjs";import{u as c}from"./context-DLtU3JQy.mjs";import{u as p,a as u}from"./privy-context-DrMxzgOR.mjs";import{M as d,E as h,a as y,b as f}from"./EnrollTotp-V5tLY1MZ.mjs";import{A as v,C as j,I as k,T as g,S as C,B as M}from"./PinInput-3SLvbnQa.mjs";import"styled-components";import"@heroicons/react/24/outline/ArrowLeftIcon";import"@heroicons/react/24/outline/ArrowRightIcon";import"@heroicons/react/24/outline/XMarkIcon";import"./internal-context-Z-fyxadS.mjs";import"ofetch";import"zustand";import"react-device-detect";import"./use-export-wallet-_wu5ex5t.mjs";import"./useWallets-BzNCTucF.mjs";import"viem";import"@privy-io/js-sdk-core";import"eventemitter3";import"viem/utils";import"./events-context-CI0iqAXA.mjs";import"tinycolor2";import"@privy-io/are-addresses-equal";import"@heroicons/react/24/outline/ChevronRightIcon";import"@heroicons/react/24/outline/DevicePhoneMobileIcon";import"@heroicons/react/24/outline/FingerPrintIcon";import"@heroicons/react/24/outline/MinusCircleIcon";import"@heroicons/react/24/outline/PhoneIcon";import"./Chip-D2-wZOHJ.mjs";import"./LoadingSkeleton-U6-3yFwI.mjs";import"@heroicons/react/24/outline/ArrowRightEndOnRectangleIcon";import"@heroicons/react/24/outline/ClockIcon";import"./ErrorScreen-sNIfGI6q.mjs";import"lucide-react";import"./index-YDEix4mU.mjs";import"uuid";import"jose";import"@coinbase/wallet-sdk";import"@privy-io/ethereum";import"mipd";import"@privy-io/popup";import"./paths-3HW55qZg.mjs";import"./usePrivy-C_sY2Duk.mjs";import"@scure/base";import"@headlessui/react";import"@walletconnect/ethereum-provider";import"@privy-io/urls";import"./PrivyPluginContext-2QN2dVUw.mjs";import"./getEmbeddedConnectedWallet-JzK4iD-L.mjs";import"js-cookie";import"./frame-uzTmvtww.mjs";import"@privy-io/routes";import"x402/client";import"@privy-io/api-base";import"viem/accounts";import"./use-sign-with-user-signer-Do5Oi_rb.mjs";import"./reservoir-0wfhnc0j.mjs";import"./ScreenLayout-D1p_ntex.mjs";import"./Screen-Cycy3IzT.mjs";import"./index-Dq_xe9dz.mjs";import"./LinkPasskeyScreen-DmtRo8xi.mjs";import"./TodoList-CgrU7uwu.mjs";import"./CopyToClipboard-DSTf_eKU.mjs";import"./Layouts-BlFm53ED.mjs";import"./Column-C2X2MHYX.mjs";import"./LabelXs-oqZNqbm_.mjs";import"./Subtitle-CV-2yKE4.mjs";import"./Title-BnzYV3Is.mjs";import"./shared-FM0rljBt.mjs";import"@heroicons/react/24/solid/ShieldCheckIcon";import"./QrCode-B84kEIjT.mjs";import"qrcode";const w={component:()=>{let{user:w,ready:b}=p(),{data:I,onUserCloseViaDialogOrKeybindRef:A}=u(),S=c(),[P,R]=n(null),[x,E]=n(null),[F,L]=n(null),[T,U]=n(!1),[B,W]=n(!1),[q,O]=n(),z=async()=>{q?D(q):w?await H({user:w}):D(Error("Must be logged in to manage MFA")),setTimeout((()=>{R(null),E(null)}),500)};if(A.current=z,!I?.mfaEnroll)throw Error("Missing modal data for MFA enrollment screen.");let{onFailure:D,onSuccess:H,onBack:Q,mfaMethods:X,verify:$,generateTotpSecret:G,enrollTotp:K,unenrollTotp:N,enrollPasskey:V}=I.mfaEnroll,Z=w?.mfaMethods.includes("sms"),J=w?.mfaMethods.includes("totp"),Y=w?.mfaMethods.includes("passkey"),_=!!w?.phone,ee=w?.linkedAccounts.filter((e=>"passkey"===e.type)).map((e=>e.credentialId))??[];function oe(){R(null),E(null),O(void 0)}async function te(e=ee){try{O(void 0),W(!0);let o=await V(e);return await H({user:o})}catch(e){O(e)}finally{W(!1),U(!1)}}if(!b||!w||!S)/*#__PURE__*/return e(o,{children:[/*#__PURE__*/t(s,{onClose:z,backFn:Q},"header"),/*#__PURE__*/t(v,{children:/*#__PURE__*/t(d,{})}),/*#__PURE__*/t(j,{children:/*#__PURE__*/t(l,{})}),/*#__PURE__*/t(a,{})]});if("sms"===P)return null;if("totp"===P)/*#__PURE__*/return e(o,{children:[/*#__PURE__*/t(s,{backFn:oe,onClose:z},"header"),/*#__PURE__*/t(k,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/t(r,{})}),/*#__PURE__*/t(g,{children:"Remove authenticator app verification?"}),/*#__PURE__*/e(C,{children:["MFA adds an extra layer of security to your ",S?.name," account. Make sure you have other methods to secure your account."]}),/*#__PURE__*/t(M,{children:/*#__PURE__*/t(m,{$warn:!0,onClick:async function(){try{O(void 0),W(!0);let e=await N();return await H({user:e})}catch(e){O(e)}finally{W(!1),R(null)}},loading:B,children:"Remove"})}),/*#__PURE__*/t(a,{})]});if("passkey"===P){let i=I.mfaEnroll.shouldUnlinkOnUnenrollMfa??!0;/*#__PURE__*/return e(o,{children:[/*#__PURE__*/t(s,{backFn:oe,onClose:z},"header"),/*#__PURE__*/t(k,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/t(r,{})}),/*#__PURE__*/t(g,{children:"Are you sure you want to remove this passkey?"}),/*#__PURE__*/t(C,{children:i?"Removing your passkey will remove as both a verification method and a login method.":"Removing your passkey will remove as a verification method."}),/*#__PURE__*/t(M,{children:/*#__PURE__*/t(m,{$warn:!0,onClick:async function(){try{O(void 0),W(!0);let e=await V([]);return await H({user:e})}catch(e){O(e)}finally{W(!1),R(null)}},loading:B,children:"Remove"})}),/*#__PURE__*/t(a,{})]})}return 0!==X.length||Z||J||Y?"sms"===x?null:"totp"===x&&F?/*#__PURE__*/t(h,{onClose:z,onReset:oe,submitEnrollmentWithTotp:e=>async function(e){try{O(void 0),W(!0);let o=await K(e);return await H({user:o})}catch(e){O(e)}finally{W(!1),R(null)}}(e.mfaCode),error:q,totpInfo:{...F,appName:S?.name||"Privy"}}):"passkey"===x?/*#__PURE__*/t(y,{onReset:oe,onClose:z,submitEnrollmentWithPasskey:te}):/*#__PURE__*/t(f,{showIntro:!0,userMfaMethods:w.mfaMethods,appMfaMethods:S.mfa.methods,userHasAuthSms:_,backFn:Q,handleSelectMethod:async function(e){O(void 0);try{await $()}catch(e){return void O(e)}return"totp"===e?(E(e),L(null),void G().then((({totpSecret:e,totpAuthUrl:o})=>{L({authUrl:o,secret:e})})).catch((()=>{L(null),oe()}))):"passkey"===e&&1===ee.length?await te():void E(e)},isTotpLoading:"totp"===x&&!F,isPasskeyLoading:T,error:q,onClose:z,setRemovingMfaMethod:async function(e){O(void 0);try{await $()}catch(e){return void O(e)}R(e)}}):/*#__PURE__*/e(o,{children:[/*#__PURE__*/t(s,{onClose:z,backFn:Q},"header"),/*#__PURE__*/t(k,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/t(i,{})}),/*#__PURE__*/t(g,{children:"Add more security"}),/*#__PURE__*/e(C,{children:[S?.name," does not have any verification methods enabled."]}),/*#__PURE__*/t(M,{children:/*#__PURE__*/t(m,{onClick:z,children:"Close"})}),/*#__PURE__*/t(a,{})]})}};export{w as MfaAuthEnrollmentFlowScreen,w as default};