UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

4 lines (3 loc) 2.55 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-WTldtXS8.mjs";import{u as m,c,b as d}from"./internal-context-Z-fyxadS.mjs";import{a as p}from"./index-BBRkihRn.mjs";import{u,a as h}from"./get-is-unified-wallet-Boa8DYrQ.mjs";import{F as g,a1 as f,V as y}from"./useActiveWallet-3RHPIBxJ.mjs";import{E,P as S}from"./ModalHeader-D8-mhjp4.mjs";import{C as b}from"./Chip-D2-wZOHJ.mjs";import{I as v,a as k}from"./EmailInputForm-Dgoii4vf.mjs";import{E as j}from"./ErrorMessage-D8VaAP5m.mjs";const C=/*#__PURE__*/t(((t,l)=>{let[y,v]=o(t.defaultValue||""),[k,C]=o(""),[T,A]=o(!1),{authenticated:D}=u(),{initLoginWithEmail:L}=m(),{navigate:M,setModalData:I,currentScreen:U,data:F}=h(),{enabled:N,token:W}=p(),[R,V]=o(!1),{accountType:_}=g(),q=s();n((()=>{!y&&q.disablePlusEmails&&F?.inlineError?.error instanceof c&&F?.inlineError?.error.privyErrorCode===d.DISALLOWED_PLUS_EMAIL&&!k&&C("Please enter a valid email address without a '+'."),k&&C("")}),[y]);let H=f(y),K=T||!H,O=()=>{var e;I({login:F?.login,inlineError:void 0}),!N||W||D?(e=W,A(!0),L({email:y,captchaToken:e,disableSignup:F?.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:y,captchaToken:e,withPrivyUi:!0}),userIntentRequired:!1,onSuccessNavigateTo:"AwaitingPasswordlessCodeScreen",onErrorNavigateTo:"ErrorScreen"}}),M("CaptchaScreen"))};/*#__PURE__*/return e(r,{children:[/*#__PURE__*/e(w,{children:[k&&/*#__PURE__*/a(j,{style:{display:"block",marginTop:"0.25rem",textAlign:"left"},children:k}),/*#__PURE__*/e(x,{stacked:t.stacked,$error:!!k,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:()=>V(!0),onChange:e=>v(e.target.value),onKeyUp:e=>{"Enter"===e.key&&O()},value:y,autoComplete:"email"}),"email"!==_||R?t.stacked?/*#__PURE__*/a("span",{}):/*#__PURE__*/a(E,{isSubmitting:T,onClick:O,disabled:K,children:"Submit"}):/*#__PURE__*/a(b,{color:"gray",children:"Recent"})]})]}),t.stacked?/*#__PURE__*/a(S,{loadingText:null,loading:T,disabled:K,onClick:O,style:{width:"100%"},children:"Submit"}):null]})}));let w=v,x=k,P=l(y)` display: inline-flex; `;export{C};