@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 2.65 kB
JavaScript
import{jsxs as e,Fragment as a,jsx as r}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-Bycd1SKV.mjs";import{u as c,c as m,b as d}from"./internal-context-e-Eni5bG.mjs";import{a as p}from"./index-CCyaupaz.mjs";import{u,a as h}from"./get-is-unified-wallet-DvKS5IUO.mjs";import{F as g,a1 as f,V as y}from"./useActiveWallet-Bsy5GTCV.mjs";import{E as S,P as E}from"./Button-B8mqatRx.mjs";import{C as b}from"./Chip-Bsgj4Yc-.mjs";import{I as v,a as k}from"./EmailInputForm-B4hjCxRU.mjs";import{E as C}from"./ErrorMessage-Cx8GKGhL.mjs";const j=/*#__PURE__*/t(((t,l)=>{let[y,v]=o(t.defaultValue||""),[k,j]=o(""),[I,L]=o(!1),{authenticated:T}=u(),{initLoginWithEmail:A}=c(),{navigate:M,setModalData:D,currentScreen:N,data:U}=h(),{enabled:W,token:F}=p(),[R,V]=o(!1),{accountType:$}=g(),_=s();n((()=>{!y&&_.disablePlusEmails&&U?.inlineError?.error instanceof m&&U?.inlineError?.error.privyErrorCode===d.DISALLOWED_PLUS_EMAIL&&!k&&j("Please enter a valid email address without a '+'."),k&&j("")}),[y]);let q=f(y),z=I||!q,B=()=>{var e;D({login:U?.login,inlineError:void 0}),!W||F||T?(e=F,L(!0),A({email:y,captchaToken:e,disableSignup:U?.login?.disableSignup,withPrivyUi:!0}).then((()=>{M("AwaitingPasswordlessCodeScreen")})).catch((e=>{D({errorModalData:{error:e,previousScreen:N||"LandingScreen"}}),M("ErrorScreen")})).finally((()=>{L(!1)}))):(D({captchaModalData:{callback:e=>A({email:y,captchaToken:e,withPrivyUi:!0}),userIntentRequired:!1,onSuccessNavigateTo:"AwaitingPasswordlessCodeScreen",onErrorNavigateTo:"ErrorScreen"}}),M("CaptchaScreen"))};/*#__PURE__*/return e(a,{children:[/*#__PURE__*/e(w,{children:[k&&/*#__PURE__*/r(C,{style:{display:"block",marginTop:"0.25rem",textAlign:"left"},children:k}),/*#__PURE__*/e(x,{stacked:t.stacked,$error:!!k,children:[/*#__PURE__*/r(P,{children:/*#__PURE__*/r(i,{})}),/*#__PURE__*/r("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&&B()},value:y,autoComplete:"email"}),"email"!==$||R?t.stacked?/*#__PURE__*/r("span",{}):/*#__PURE__*/r(S,{isSubmitting:I,onClick:B,disabled:z,children:"Submit"}):/*#__PURE__*/r(b,{color:"gray",children:"Recent"})]})]}),t.stacked?/*#__PURE__*/r(E,{loadingText:null,loading:I,disabled:z,onClick:B,style:{width:"100%"},children:"Submit"}):null]})}));let w=v,x=k,P=/*#__PURE__*/l(y).withConfig({displayName:"StyledLoginMethodIconWrapper",componentId:"sc-30d3bab7-0"})(["display:inline-flex;"]);export{j as C};