UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

4 lines (3 loc) 2.58 kB
import{jsxs as e,Fragment as r,jsx as a}from"react/jsx-runtime";import{Mail as i}from"lucide-react";import{forwardRef as t,useState as o,useEffect as n}from"react";import{styled as l}from"styled-components";import{u as s}from"./context-DLtU3JQy.mjs";import{u as m,c,b as d}from"./internal-context-Z-fyxadS.mjs";import{a as p}from"./index-YDEix4mU.mjs";import{u,a as h}from"./privy-context-DrMxzgOR.mjs";import{r as g,C as f}from"./useActiveWallet-CvP7iYvj.mjs";import{B as y}from"./use-export-wallet-_wu5ex5t.mjs";import{E,P as S}from"./ModalHeader-BnVmXtvG.mjs";import{C as v}from"./Chip-D2-wZOHJ.mjs";import{I as b,a as j}from"./EmailInputForm-Dgoii4vf.mjs";import{E as k}from"./ErrorMessage-D8VaAP5m.mjs";const C=/*#__PURE__*/t(((t,l)=>{let[f,b]=o(t.defaultValue||""),[j,C]=o(""),[T,A]=o(!1),{authenticated:D}=u(),{initLoginWithEmail:L}=m(),{navigate:M,setModalData:I,currentScreen:U,data:N}=h(),{enabled:W,token:F}=p(),[R,_]=o(!1),{accountType:q}=g(),B=s();n((()=>{!f&&B.disablePlusEmails&&N?.inlineError?.error instanceof c&&N?.inlineError?.error.privyErrorCode===d.DISALLOWED_PLUS_EMAIL&&!j&&C("Please enter a valid email address without a '+'."),j&&C("")}),[f]);let H=y(f),K=T||!H,O=()=>{var e;I({login:N?.login,inlineError:void 0}),!W||F||D?(e=F,A(!0),L({email:f,captchaToken:e,disableSignup:N?.login?.disableSignup,withPrivyUi:!0}).then((()=>{M("AwaitingPasswordlessCodeScreen")})).catch((e=>{I({errorModalData:{error:e,previousScreen:U||"LandingScreen"}}),M("ErrorScreen")})).finally((()=>{A(!1)}))):(I({captchaModalData:{callback:e=>L({email:f,captchaToken:e,withPrivyUi:!0}),userIntentRequired:!1,onSuccessNavigateTo:"AwaitingPasswordlessCodeScreen",onErrorNavigateTo:"ErrorScreen"}}),M("CaptchaScreen"))};/*#__PURE__*/return e(r,{children:[/*#__PURE__*/e(x,{children:[j&&/*#__PURE__*/a(k,{style:{display:"block",marginTop:"0.25rem",textAlign:"left"},children:j}),/*#__PURE__*/e(w,{stacked:t.stacked,$error:!!j,children:[/*#__PURE__*/a(P,{children:/*#__PURE__*/a(i,{})}),/*#__PURE__*/a("input",{ref:l,id:"email-input",className:"login-method-button",type:"email",placeholder:"your@email.com",onFocus:()=>_(!0),onChange:e=>b(e.target.value),onKeyUp:e=>{"Enter"===e.key&&O()},value:f,autoComplete:"email"}),"email"!==q||R?t.stacked?/*#__PURE__*/a("span",{}):/*#__PURE__*/a(E,{isSubmitting:T,onClick:O,disabled:K,children:"Submit"}):/*#__PURE__*/a(v,{color:"gray",children:"Recent"})]})]}),t.stacked?/*#__PURE__*/a(S,{loadingText:null,loading:T,disabled:K,onClick:O,style:{width:"100%"},children:"Submit"}):null]})}));let x=b,w=j,P=l(f)` display: inline-flex; `;export{C};