1import{l as H,r as s,j as t,t as we,e as Ke,bv as Ye,k as Xe,d as Je,h as U,G as Qe,H as Ze,J as et,O as tt,cV as nt,P as rt,Q as at,T as st,dg as Pe,x as q,a as ve,V as je,X as Se,K as ot,dh as Ne,di as it,dj as lt}from"./index-f--GfbGy.js";import{D as ct}from"./dot-DSPD-WDm.js";import{s as ut}from"./passkeys-CLLa1E6T.js";import{M as dt}from"./mail-u4N8664d.js";import{A as Te}from"./arrow-left-CibCCW_O.js";var pt={name:"@lovable.dev/cloud-auth-js",version:"1.1.2",description:"Lovable Cloud Auth JS",main:"./dist/index.cjs",module:"./dist/index.js",types:"./dist/index.d.ts",type:"module",files:["dist"],scripts:{build:"tsup src/index.ts --format cjs,esm --dts --outDir dist",dev:"tsup src/index.ts --format cjs,esm --dts --watch",test:"vitest run",typecheck:"tsgo --noEmit",prepublishOnly:"npm run clean && npm run build",clean:"rimraf dist"},keywords:["lovable","oauth","authentication"],license:"MIT",devDependencies:{"@types/node":"^22",jsdom:"^26",rimraf:"^5.0.0",tsup:"^7.2.0",typescript:"^5",vitest:"^4.1.0"}},mt="authorization_response",ht="/~oauth/initiate",ft=["https://oauth.lovable.app","https://lovable.dev"],gt="lovable://oauth-callback",xt="http://127.0.0.1/iframe-oauth/callback",vt=500,wt=12e4;function bt(n){let r;const e=new Promise(l=>{r=l}),o=l=>{if(!n.some(E=>l.origin===E))return;const v=l.data;!v||typeof v!="object"||v.type===mt&&r(v.response)},x=()=>{window.removeEventListener("message",o)};return window.addEventListener("message",o),{cleanup:x,messagePromise:e}}function yt(n){const r=window.screenX!==0||window.screenY!==0||!n,e=r?window.outerWidth*.5:window.screen.width*.5,o=r?window.outerHeight*.5:window.screen.height*.5,x=r?window.screenX+(window.outerWidth-e)/2:(window.screen.width-e)/2,l=r?window.screenY+(window.outerHeight-o)/2:(window.screen.height-o)/2;return{width:e,height:o,left:x,top:l}}function Ae(n,r){return n.state!==r?{error:new Error("State is invalid")}:n.error?n.error==="legacy_flow"?{error:new Error("This flow is not supported in Preview mode. Please open the app in a new tab to sign in.")}:{error:new Error(n.error_description??"Sign in failed")}:!n.access_token||!n.refresh_token?{error:new Error("No tokens received")}:{tokens:{access_token:n.access_token,refresh_token:n.refresh_token},error:null}}function _t(){const n=navigator.userAgent;return!!(/iPhone|iPad|iPod|Android/i.test(n)||/Macintosh/i.test(n)&&navigator.maxTouchPoints>1)}function jt(){return typeof crypto<"u"&&crypto.getRandomValues?[...crypto.getRandomValues(new Uint8Array(16))].map(n=>n.toString(16).padStart(2,"0")).join(""):Math.random().toString(36).substring(2)+Date.now().toString(36)}function St(n={}){const r=n.oauthBrokerUrl??ht,e=n.supportedOAuthOrigins??ft;async function o(x,l={}){let h=!1;try{h=window.self!==window.top}catch{h=!0}const v=navigator.userAgent,E=/LovableApp\//.test(v),k=!E&&/lovable/i.test(v),T=jt();let _=l.redirect_uri??window.location.origin;E&&h?_=gt:k&&h&&(_=xt);const b=new URLSearchParams({...l.extraParams,provider:x,redirect_uri:_,state:T});if(!h)return window.location.href=`${r}?${b.toString()}`,{error:null,redirected:!0};!E&&!k&&b.set("response_mode","web_message");const y=`${r}?${b.toString()}`,j=k?[...e,window.location.origin]:e,{messagePromise:S,cleanup:A}=bt(j);let u;if(_t())u=window.open(y,"_blank");else{const{width:w,height:M,left:C,top:F}=yt(h);u=window.open(y,"oauth",`width=${w},height=${M},left=${C},top=${F}`)}if(!u&&(E||k)){let w;const M=new Promise((C,F)=>{w=setTimeout(()=>{F(new Error("OAuth timed out waiting for response"))},wt)});try{const C=await Promise.race([S,M]);return Ae(C,T)}catch(C){return{error:C instanceof Error?C:new Error(String(C))}}finally{w&&clearTimeout(w),A()}}if(!u)return A(),{error:new Error("Popup was blocked")};let I;const G=new Promise((w,M)=>{I=setInterval(()=>{u.closed&&(clearInterval(I),M(new Error("Sign in was cancelled")))},vt)});try{const w=await Promise.race([S,G]);return Ae(w,T)}catch(w){return{error:w instanceof Error?w:new Error(String(w))}}finally{clearInterval(I),A(),u?.close()}}return{signInWithOAuth:o}}typeof window<"u"&&(window.__lovable_cloud_auth_js_version=pt.version);function Et(n={}){return St(n)}const kt=Et(),Me={auth:{signInWithOAuth:async(n,r)=>{const e=await kt.signInWithOAuth(n,{redirect_uri:r?.redirect_uri,extraParams:{...r?.extraParams}});if(e.redirected||e.error)return e;try{await H.auth.setSession(e.tokens)}catch(o){return{error:o instanceof Error?o:new Error(String(o))}}return e}}};
1var Ct=Object.defineProperty,Pt=Object.defineProperties,Nt=Object.getOwnPropertyDescriptors,be=Object.getOwnPropertySymbols,Oe=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable,Re=(n,r,e)=>r in n?Ct(n,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[r]=e,Tt=(n,r)=>{for(var e in r||(r={}))Oe.call(r,e)&&Re(n,e,r[e]);if(be)for(var e of be(r))Le.call(r,e)&&Re(n,e,r[e]);return n},At=(n,r)=>Pt(n,Nt(r)),Mt=(n,r)=>{var e={};for(var o in n)Oe.call(n,o)&&r.indexOf(o)<0&&(e[o]=n[o]);if(n!=null&&be)for(var o of be(n))r.indexOf(o)<0&&Le.call(n,o)&&(e[o]=n[o]);return e};function Rt(n){let r=setTimeout(n,0),e=setTimeout(n,10),o=setTimeout(n,50);return[r,e,o]}function It(n){let r=s.useRef();return s.useEffect(()=>{r.current=n}),r.current}var Ot=18,De=40,Lt=`${De}px`,Dt=["[data-lastpass-icon-root]","com-1password-button","[data-dashlanecreated]",'[style$="2147483647 !important;"]'].join(",");function Ft({containerRef:n,inputRef:r,pushPasswordManagerStrategy:e,isFocused:o}){let[x,l]=s.useState(!1),[h,v]=s.useState(!1),[E,k]=s.useState(!1),T=s.useMemo(()=>e==="none"?!1:(e==="increase-width"||e==="experimental-no-flickering")&&x&&h,[x,h,e]),_=s.useCallback(()=>{let b=n.current,y=r.current;if(!b||!y||E||e==="none")return;let j=b,S=j.getBoundingClientRect().left+j.offsetWidth,A=j.getBoundingClientRect().top+j.offsetHeight/2,u=S-Ot,I=A;document.querySelectorAll(Dt).length===0&&document.elementFromPoint(u,I)===b||(l(!0),k(!0))},[n,r,E,e]);return s.useEffect(()=>{let b=n.current;if(!b||e==="none")return;function y(){let S=window.innerWidth-b.getBoundingClientRect().right;v(S>=De)}y();let j=setInterval(y,1e3);return()=>{clearInterval(j)}},[n,e]),s.useEffect(()=>{let b=o||document.activeElement===r.current;if(e==="none"||!b)return;let y=setTimeout(_,0),j=setTimeout(_,2e3),S=setTimeout(_,5e3),A=setTimeout(()=>{k(!0)},6e3);return()=>{clearTimeout(y),clearTimeout(j),clearTimeout(S),clearTimeout(A)}},[r,o,e,_]),{hasPWMBadge:x,willPushPWMBadge:T,PWM_BADGE_SPACE_WIDTH:Lt}}var Fe=s.createContext({}),We=s.forwardRef((n,r)=>{var e=n,{value:o,onChange:x,maxLength:l,textAlign:h="left",pattern:v,placeholder:E,inputMode:k="numeric",onComplete:T,pushPasswordManagerStrategy:_="increase-width",pasteTransformer:b,containerClassName:y,noScriptCSSFallback:j=Wt,render:S,children:A}=e,u=Mt(e,["value","onChange","maxLength","textAlign","pattern","placeholder","inputMode","onComplete","pushPasswordManagerStrategy","pasteTransformer","containerClassName","noScriptCSSFallback","render","children"]),I,G,w,M,C;let[F,he]=s.useState(typeof u.defaultValue=="string"?u.defaultValue:""),f=o??F,W=It(f),O=s.useCallback(i=>{x?.(i),he(i)},[x]),P=s.useMemo(()=>v?typeof v=="string"?new RegExp(v):v:null,[v]),g=s.useRef(null),$=s.useRef(null),oe=s.useRef({value:f,onChange:O,isIOS:typeof window<"u"&&((G=(I=window?.CSS)==null?void 0:I.supports)==null?void 0:G.call(I,"-webkit-touch-callout","none"))}),L=s.useRef({prev:[(w=g.current)==null?void 0:w.selectionStart,(M=g.current)==null?void 0:M.selectionEnd,(C=g.current)==null?void 0:C.selectionDirection]});s.useImperativeHandle(r,()=>g.current,[]),s.useEffect(()=>{let i=g.current,a=$.current;if(!i||!a)return;oe.current.value!==i.value&&oe.current.onChange(i.value),L.current.prev=[i.selectionStart,i.selectionEnd,i.selectionDirection];function c(){if(document.activeElement!==i){R(null),Z(null);return}let d=i.selectionStart,N=i.selectionEnd,xe=i.selectionDirection,D=i.maxLength,te=i.value,V=L.current.prev,X=-1,J=-1,ne;if(te.length!==0&&d!==null&&N!==null){let Ve=d===N,qe=d===te.length&&te.length<D;if(Ve&&!qe){let re=d;if(re===0)X=0,J=1,ne="forward";else if(re===D)X=re-1,J=re,ne="backward";else if(D>1&&te.length>1){let _e=0;if(V[0]!==null&&V[1]!==null){ne=re<V[1]?"backward":"forward";let Ge=V[0]===V[1]&&V[0]<D;ne==="backward"&&!Ge&&(_e=-1)}X=_e+re,J=_e+re+1}}X!==-1&&J!==-1&&X!==J&&g.current.setSelectionRange(X,J,ne)}let ke=X!==-1?X:d,Ce=J!==-1?J:N,ze=ne??xe;R(ke),Z(Ce),L.current.prev=[ke,Ce,ze]}if(document.addEventListener("selectionchange",c,{capture:!0}),c(),document.activeElement===i&&Q(!0),!document.getElementById("input-otp-style")){let d=document.createElement("style");if(d.id="input-otp-style",document.head.appendChild(d),d.sheet){let N="background: transparent !important; color: transparent !important; border-color: transparent !important; opacity: 0 !important; box-shadow: none !important; -webkit-box-shadow: none !important; -webkit-text-fill-color: transparent !important;";me(d.sheet,"[data-input-otp]::selection { background: transparent !important; color: transparent !important; }"),me(d.sheet,`[data-input-otp]:autofill { ${N} }`),me(d.sheet,`[data-input-otp]:-webkit-autofill { ${N} }
1`),me(d.sheet,"@supports (-webkit-touch-callout: none) { [data-input-otp] { letter-spacing: -.6em !important; font-weight: 100 !important; font-stretch: ultra-condensed; font-optical-sizing: none !important; left: -1px !important; right: 1px !important; } }"),me(d.sheet,"[data-input-otp] + * { pointer-events: all !important; }")}}let p=()=>{a&&a.style.setProperty("--root-height",`${i.clientHeight}px`)};p();let m=new ResizeObserver(p);return m.observe(i),()=>{document.removeEventListener("selectionchange",c,{capture:!0}),m.disconnect()}},[]);let[de,fe]=s.useState(!1),[K,Q]=s.useState(!1),[Y,R]=s.useState(null),[B,Z]=s.useState(null);s.useEffect(()=>{Rt(()=>{var i,a,c,p;(i=g.current)==null||i.dispatchEvent(new Event("input"));let m=(a=g.current)==null?void 0:a.selectionStart,d=(c=g.current)==null?void 0:c.selectionEnd,N=(p=g.current)==null?void 0:p.selectionDirection;m!==null&&d!==null&&(R(m),Z(d),L.current.prev=[m,d,N])})},[f,K]),s.useEffect(()=>{W!==void 0&&f!==W&&W.length<l&&f.length===l&&T?.(f)},[l,T,W,f]);let z=Ft({containerRef:$,inputRef:g,pushPasswordManagerStrategy:_,isFocused:K}),ie=s.useCallback(i=>{let a=i.currentTarget.value.slice(0,l);if(a.length>0&&P&&!P.test(a)){i.preventDefault();return}typeof W=="string"&&a.length<W.length&&document.dispatchEvent(new Event("selectionchange")),O(a)},[l,O,W,P]),ge=s.useCallback(()=>{var i;if(g.current){let a=Math.min(g.current.value.length,l-1),c=g.current.value.length;(i=g.current)==null||i.setSelectionRange(a,c),R(a),Z(c)}Q(!0)},[l]),le=s.useCallback(i=>{var a,c;let p=g.current;if(!b&&(!oe.current.isIOS||!i.clipboardData||!p))return;let m=i.clipboardData.getData("text/plain"),d=b?b(m):m;i.preventDefault();let N=(a=g.current)==null?void 0:a.selectionStart,xe=(c=g.current)==null?void 0:c.selectionEnd,D=(N!==xe?f.slice(0,N)+d+f.slice(xe):f.slice(0,N)+d+f.slice(N)).slice(0,l);if(D.length>0&&P&&!P.test(D))return;p.value=D,O(D);let te=Math.min(D.length,l-1),V=D.length;p.setSelectionRange(te,V),R(te),Z(V)},[l,O,P,f]),pe=s.useMemo(()=>({position:"relative",cursor:u.disabled?"default":"text",userSelect:"none",WebkitUserSelect:"none",pointerEvents:"none"}),[u.disabled]),ee=s.useMemo(()=>({position:"absolute",inset:0,width:z.willPushPWMBadge?`calc(100% + ${z.PWM_BADGE_SPACE_WIDTH})`:"100%",clipPath:z.willPushPWMBadge?`inset(0 ${z.PWM_BADGE_SPACE_WIDTH} 0 0)`:void 0,height:"100%",display:"flex",textAlign:h,opacity:"1",color:"transparent",pointerEvents:"all",background:"transparent",caretColor:"transparent",border:"0 solid transparent",outline:"0 solid transparent",boxShadow:"none",lineHeight:"1",letterSpacing:"-.5em",fontSize:"var(--root-height)",fontFamily:"monospace",fontVariantNumeric:"tabular-nums"}),[z.PWM_BADGE_SPACE_WIDTH,z.willPushPWMBadge,h]),ce=s.useMemo(()=>s.createElement("input",At(Tt({autoComplete:u.autoComplete||"one-time-code"},u),{"data-input-otp":!0,"data-input-otp-placeholder-shown":f.length===0||void 0,"data-input-otp-mss":Y,"data-input-otp-mse":B,inputMode:k,pattern:P?.source,"aria-placeholder":E,style:ee,maxLength:l,value:f,ref:g,onPaste:i=>{var a;le(i),(a=u.onPaste)==null||a.call(u,i)},onChange:ie,onMouseOver:i=>{var a;fe(!0),(a=u.onMouseOver)==null||a.call(u,i)},onMouseLeave:i=>{var a;fe(!1),(a=u.onMouseLeave)==null||a.call(u,i)},onFocus:i=>{var a;ge(),(a=u.onFocus)==null||a.call(u,i)},onBlur:i=>{var a;Q(!1),(a=u.onBlur)==null||a.call(u,i)}})),[ie,ge,le,k,ee,l,B,Y,u,P?.source,f]),ue=s.useMemo(()=>({slots:Array.from({length:l}).map((i,a)=>{var c;let p=K&&Y!==null&&B!==null&&(Y===B&&a===Y||a>=Y&&a<B),m=f[a]!==void 0?f[a]:null,d=f[0]!==void 0?null:(c=E?.[a])!=null?c:null;return{char:m,placeholderChar:d,isActive:p,hasFakeCaret:p&&m===null}}),isFocused:K,isHovering:!u.disabled&&de}),[K,de,l,B,Y,u.disabled,f]),ye=s.useMemo(()=>S?S(ue):s.createElement(Fe.Provider,{value:ue},A),[A,ue,S]);return s.createElement(s.Fragment,null,j!==null&&s.createElement("noscript",null,s.createElement("style",null,j)),s.createElement("div",{ref:$,"data-input-otp-container":!0,style:pe,className:y},ye,s.createElement("div",{style:{position:"absolute",inset:0,pointerEvents:"none"}},ce)))});We.displayName="Input";function me(n,r){try{n.insertRule(r)}catch{console.error("input-otp could not insert CSS rule:",r)}}var Wt=` 2[data-input-otp] { 3 --nojs-bg: white !important; 4 --nojs-fg: black !important; 5 6 background-color: var(--nojs-bg) !important; 7 color: var(--nojs-fg) !important; 8 caret-color: var(--nojs-fg) !important; 9 letter-spacing: .25em !important; 10 text-align: center !important; 11 border: 1px solid var(--nojs-fg) !important; 12 border-radius: 4px !important; 13 width: 100% !important; 14} 15@media (prefers-color-scheme: dark) { 16 [data-input-otp] { 17 --nojs-bg: black !important; 18 --nojs-fg: white !important; 19 } 20}`;const Be=s.forwardRef(({className:n,containerClassName:r,...e},o)=>t.jsx(We,{ref:o,containerClassName:we("flex items-center gap-2 has-[:disabled]:opacity-50",r),className:we("disabled:cursor-not-allowed",n),...e}));Be.displayName="InputOTP";const Ue=s.forwardRef(({className:n,...r},e)=>t.jsx("div",{ref:e,className:we("flex items-center",n),...r}));Ue.displayName="InputOTPGroup";const ae=s.forwardRef(({index:n,className:r,...e},o)=>{const x=s.useContext(Fe),{char:l,hasFakeCaret:h,isActive:v}=x.slots[n];return t.jsxs("div",{ref:o,className:we("relative flex h-10 w-10 items-center justify-center border-y border-e border-input text-sm transition-all first:rounded-s-md first:border-s last:rounded-e-md",v&&"z-10 ring-2 ring-ring ring-offset-background",r),...e,children:[l,h&&t.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:t.jsx("div",{className:"animate-caret-blink h-4 w-px bg-foreground duration-1000"})})]})});ae.displayName="InputOTPSlot";const Bt=s.forwardRef(({...n},r)=>t.jsx("div",{ref:r,role:"separator",...n,children:t.jsx(ct,{})}));Bt.displayName="InputOTPSeparator";
20const Ut={invalid_phone:"That phone number doesn't look valid. Include the country code, e.g. +15551234567.",invalid_code:"That code didn't match. Double-check and try again.",code_expired:"That code expired. Request a new one.",sms_send_failed:"We couldn't send the code. Try again in a moment.",rate_limited:"You're going too fast. Try again in a moment."};function Ee(n,r){return n?Ut[n]??r:r}class se extends Error{code;constructor(r,e){super(e),this.name="SmsAuthError",this.code=r}}function He(n){const r=n.toLowerCase();return r.includes("invalid_phone")?"invalid_phone":r.includes("invalid_code")?"invalid_code":r.includes("code_expired")?"code_expired":r.includes("sms_send_failed")?"sms_send_failed":r.includes("rate_limited")||r.includes("rate")||r.includes("too many")?"rate_limited":r.includes("expired")?"code_expired":r.includes("invalid")&&r.includes("phone")?"invalid_phone":r.includes("token")||r.includes("otp")||r.includes("invalid")?"invalid_code":"unknown"}async function $e(n){const r=n?.context;if(r)try{const e=await r.clone().json();if(e&&typeof e.error=="string")return e.error;if(e&&typeof e.detail=="string")return e.detail}catch{}return n?.message??""}async function Ht(n){const{error:r}=await H.functions.invoke("bird-sms-otp-start",{body:{phone:n}});if(r){const e=await $e(r),o=He(e);throw new se(o,Ee(o,e||"Could not send code"))}return{ok:!0}}async function $t(n){const{data:r,error:e}=await H.functions.invoke("bird-sms-otp-verify",{body:n});if(e){const h=await $e(e),v=He(h);throw new se(v,Ee(v,h||"Could not verify code"))}const o=r?.error;if(o)throw new se(o,Ee(o,"Could not verify code"));const x=r?.session;if(!x?.access_token||!x?.refresh_token)throw new se("unknown","Could not verify code");const{error:l}=await H.auth.setSession({access_token:x.access_token,refresh_token:x.refresh_token});if(l)throw new se("unknown",l.message);return{ok:!0}}function zt(n){return lt(n)}function Ie(n){if(!n||!n.startsWith("+"))return n;const r=n.slice(1);if(r.length<=4)return n;const e=r.slice(-4),o=r.length-4;return`+${"â¢".repeat(Math.min(o,6))} ${e}`}function Xt(){const n=Ke(),r=Ye(),{t:e}=Xe(),{user:o,loading:x}=Je(),[l,h]=s.useState("phone"),[v,E]=s.useState(""),[k,T]=s.useState(!1),[_,b]=s.useState(null),[y,j]=s.useState("phone"),[S,A]=s.useState(""),[u,I]=s.useState(""),[G,w]=s.useState(""),[M,C]=s.useState(!1),[F,he]=s.useState(!1),[f,W]=s.useState(!1),[O,P]=s.useState(0),[g,$]=s.useState(null),[oe,L]=s.useState(null),de=s.useRef(null),fe=()=>{const a=de.current?.querySelector("input");if(a)try{a.focus({preventScroll:!0})}catch{a.focus()}}
20,K=new URLSearchParams(r.search),Q=K.get("next")??K.get("redirect"),R=(Q&&Q.startsWith("/")?Q:null)??"/me",B=s.useRef(null);s.useEffect(()=>{x||(B.current===null&&(B.current=!!o),o&&y!=="name"&&(B.current?U.info(e("auth.toast.already_signed_in")):U.success(e("auth.toast.signed_in")),n(R,{replace:!0})))},[o,x,n,R,y,e]),s.useEffect(()=>{if(O<=0)return;const a=setTimeout(()=>P(c=>c-1),1e3);return()=>clearTimeout(a)},[O]),s.useEffect(()=>{new URLSearchParams(r.search).get("mode")==="phone"&&h("phone")},[r.search]);const Z=async a=>{a.preventDefault();const c=v.trim();if(!c||!c.includes("@")){U.error(e("auth.email.invalid"));return}T(!0);const p=new URL("/auth/callback",window.location.origin);p.searchParams.set("next",R);const{error:m}=await H.auth.signInWithOtp({email:c,options:{emailRedirectTo:p.toString(),shouldCreateUser:!0}});if(T(!1),m){U.error(m.message);return}b(c),U.success(e("auth.email.toast_sent"))},z=async a=>{if(a?.preventDefault(),$(null),!zt(S)){$(e("auth.phone.invalid"));return}if(!M){$(e("auth.phone.consent_required"));return}const c=it(S);he(!0);let p="",m="";try{await Ht(c)}catch(d){d instanceof se?(p=d.code,m=d.message):m=d instanceof Error?d.message:String(d)}if(he(!1),m){$(m),p==="rate_limited"&&U.error(e("auth.phone.rate_limited"));return}I(c),j("code"),w(""),L(null),P(30),U.success(e("auth.phone.toast_sent",{phone:Ie(c)}))},[ie,ge]=s.useState(""),[le,pe]=s.useState(!1),[ee,ce]=s.useState(null),ue=async a=>{if(L(null),!u){L(e("auth.code.need_new")),j("phone");return}W(!0);let c="",p="";try{await $t({phone:u,code:a})}catch(m){m instanceof se?(c=m.code,p=m.message):p=m instanceof Error?m.message:String(m)}if(W(!1),p){L(c==="code_expired"?e("auth.code.expired"):c==="invalid_code"?e("auth.code.invalid"):p),w(""),requestAnimationFrame(()=>fe());return}try{const{data:{user:m}}=await H.auth.getUser();if(m){const{data:d}=await H.from("profiles").select("first_name").eq("id",m.id).maybeSingle();if(!d?.first_name?.trim()){j("name");return}}}catch{}n(R,{replace:!0})},ye=async a=>{a?.preventDefault(),ce(null);const c=ie.trim();if(c.length<1||c.length>60){ce("Please enter a first name (1â60 characters).");return}pe(!0);try{const{data:{user:p}}=await H.auth.getUser();p&&(await H.from("profiles").update({first_name:c,full_name:c}).eq("id",p.id).is("full_name",null),await H.from("profiles").update({first_name:c}).eq("id",p.id))}catch(p){ce(p instanceof Error?p.message:String(p)),pe(!1);return}pe(!1),n(R,{replace:!0})},i=()=>{n(R,{replace:!0})};return t.jsxs("div",{className:"flex min-h-screen items-center justify-center bg-muted/30 px-4",children:[t.jsx(Qe,{}),t.jsxs(Ze,{children:[t.jsx("title",{children:e("auth.helmet.title")}),t.jsx("meta",{name:"description",content:e("auth.helmet.description")}),t.jsx("meta",{name:"robots",content:"noindex,follow"}),t.jsx("meta",{property:"og:title",content:"lo.st â Lost something? Let's get it home."}),t.jsx("meta",{property:"og:description",content:"Private by design, no app required."}),t.jsx("meta",{property:"og:url",content:`https://lo.st${r.pathname}`}),t.jsx("meta",{property:"og:type",content:"website"}),t.jsx("meta",{property:"og:image",content:"https://lo.st/og/default.jpg"}),t.jsx("meta",{name:"twitter:card",content:"summary_large_image"}),t.jsx("meta",{name:"twitter:image",content:"https://lo.st/og/default.jpg"})]}),t.jsxs(et,{className:"w-full max-w-md",children:[t.jsxs(tt,{children:[t.jsx("div",{className:"mb-2 flex justify-center",children:t.jsx(nt,{size:"lg",className:"scale-[1.725] origin-center"})}),t.jsx(rt,{className:"sr-only",children:"lo.st"}),t.jsxs(at,{children:[l==="email"&&!_&&e("auth.intro.email"),l==="email"&&_&&e("auth.intro.email_sent",{email:_}),l==="phone"&&y==="phone"&&e("auth.intro.phone"),l==="phone"&&y==="code"&&(u?e("auth.intro.co
20de_with_phone",{phone:Ie(u)}):e("auth.intro.code"))]}),!_&&y==="phone"&&t.jsxs("div",{className:"mt-3 inline-flex w-full rounded-lg bg-surface-sunken p-1 text-sm",children:[t.jsx("button",{type:"button",onClick:()=>h("phone"),className:`flex-1 rounded-md px-3 py-1.5 font-medium transition ${l==="phone"?"bg-background shadow-card text-foreground":"text-muted-foreground"}`,children:e("auth.tabs.phone")}),t.jsx("button",{type:"button",onClick:()=>h("email"),className:`flex-1 rounded-md px-3 py-1.5 font-medium transition ${l==="email"?"bg-background shadow-card text-foreground":"text-muted-foreground"}`,children:e("auth.tabs.email")})]})]}),t.jsx(st,{children:l==="email"?t.jsxs(t.Fragment,{children:[_?t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"rounded-lg border border-foreground/10 bg-surface p-4 text-sm",children:[t.jsx("p",{className:"text-foreground",children:t.jsx(Pe,{i18nKey:"auth.email.sent_body",values:{email:_},components:[t.jsx("span",{className:"font-medium"},"0")]})}),t.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:e("auth.email.sent_hint")})]}),t.jsx(q,{asChild:!0,type:"button",variant:"secondary",className:"w-full",children:t.jsx(ve,{to:`/auth/code?email=${encodeURIComponent(_)}`,children:e("auth.email.enter_code_instead")})}),t.jsx(q,{type:"button",variant:"outline",className:"w-full",onClick:()=>{b(null),E("")},children:e("auth.email.use_diff_email")})]}):t.jsxs("form",{onSubmit:Z,className:"space-y-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(je,{htmlFor:"email",children:e("auth.email.label")}),t.jsx(Se,{id:"email",type:"email",autoComplete:"email",inputMode:"email",placeholder:e("auth.email.placeholder"),required:!0,value:v,onChange:a=>E(a.target.value)})]}),t.jsxs(q,{type:"submit",className:"w-full",disabled:k,children:[t.jsx(dt,{className:"me-2 h-4 w-4"}),e(k?"auth.email.sending":"auth.email.send_link")]}),t.jsxs("p",{className:"text-center text-xs text-muted-foreground",children:[e("auth.email.code_fallback_prompt")," ",t.jsx(ve,{to:"/auth/code",className:"underline",children:e("auth.email.code_fallback_link")})]})]}),t.jsxs("div",{className:"my-4 flex items-center gap-2 text-xs text-muted-foreground",children:[t.jsx("div",{className:"h-px flex-1 bg-border"}),t.jsx("span",{children:e("auth.divider_or")}),t.jsx("div",{className:"h-px flex-1 bg-border"})]}),t.jsxs(q,{type:"button",variant:"outline",className:"mb-2 w-full",onClick:async()=>{const a=await Me.auth.signInWithOAuth("google",{redirect_uri:window.location.origin});a.error&&U.error(a.error.message??e("auth.cta.google_failed"))},children:[t.jsxs("svg",{className:"me-2 h-4 w-4",viewBox:"0 0 24 24","aria-hidden":"true",children:[t.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}),t.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.99.66-2.25 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),t.jsx("path",{fill:"#FBBC05",d:"M5.84 14.1c-.22-.66-.35-1.36-.35-2.1s.13-1.44.35-2.1V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l3.66-2.83z"}),t.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.83C6.71 7.31 9.14 5.38 12 5.38z"})]}),e("auth.cta.google")]}),t.jsxs(q,{type:"button",variant:"outline",className:"mb-2 w-full",onClick:async()=>{const a=await Me.auth.signInWithOAuth("apple",{redirect_uri:window.location.origin,extraParams:{scope:"name email",response_mode:"form_post"}});a.error&&U.error(a.error.message??e("auth.cta.apple_failed"))},children:[t.jsx("svg",{className:"me-2 h-4 w-4",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:t.jsx("path",{d:"M17.05 12.04c-.03-2.92 2.39-4.32 2.5-4.39-1.36-1.99-3.48-2.27-4.24-2.3-1.81-.18-3.53 1.06-4.45 1.06-.92 0-2.34-1.04-3.85-1.01-1.98.03-3.81 1.15-4.83 2.92-2.06 3.57-.53 8.85 1.48 11.75.98 1.42 2.15 3.01 3.69 2.96 1.48-.06 2.04-.96 3.83-.96 1.79 0 2.29.96 3.86.93 1.59
20-.03 2.6-1.45 3.57-2.87 1.13-1.65 1.59-3.25 1.61-3.33-.04-.02-3.09-1.19-3.17-4.76zM14.13 3.7c.81-.99 1.36-2.36 1.21-3.72-1.17.05-2.59.78-3.43 1.76-.75.87-1.41 2.27-1.23 3.6 1.31.1 2.65-.66 3.45-1.64z"})}),e("auth.cta.apple")]}),t.jsxs(q,{type:"button",variant:"outline",className:"mb-2 w-full",onClick:async()=>{try{await ut(),n("/dashboard",{replace:!0})}catch(a){U.error(a.message)}},children:[t.jsx(ot,{className:"me-2 h-4 w-4"}),e("auth.cta.passkey")]}),t.jsx("button",{type:"button",className:"mt-3 w-full text-center text-xs text-muted-foreground underline",onClick:()=>h("phone"),children:e("auth.use_phone_instead")}),t.jsx("p",{className:"mt-4 text-center text-xs text-muted-foreground",children:e("auth.passwordless_note")})]}):y==="phone"?t.jsxs(t.Fragment,{children:[t.jsxs("form",{onSubmit:z,className:"space-y-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(je,{htmlFor:"phone",children:e("auth.phone.label")}),t.jsx(Se,{id:"phone",type:"tel",autoComplete:"tel",inputMode:"tel",placeholder:e("auth.phone.placeholder"),required:!0,value:S,onChange:a=>{A(a.target.value),g&&$(null)},"aria-invalid":g?!0:void 0}),Ne(S)?t.jsxs("p",{className:"text-xs text-muted-foreground",children:[e("auth.phone.preview")," ",t.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Ne(S)})]}):t.jsx("p",{className:"text-xs text-muted-foreground",children:e("auth.phone.helper")})]}),g&&t.jsx("p",{role:"alert",className:"rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs text-destructive",children:g}),t.jsxs("label",{className:"flex items-start gap-2 text-xs text-muted-foreground leading-snug",children:[t.jsx("input",{type:"checkbox",className:"mt-0.5 h-3.5 w-3.5 shrink-0",checked:M,onChange:a=>C(a.target.checked)}),t.jsx("span",{children:t.jsx(Pe,{i18nKey:"auth.phone.consent",components:[t.jsx(ve,{to:"/legal/sms",className:"underline"},"0"),t.jsx(ve,{to:"/legal/privacy",className:"underline"},"1")]})})]}),t.jsx(q,{type:"submit",className:"w-full",disabled:F||!M,children:e(F?"auth.phone.sending":"auth.phone.send_code")})]}),t.jsxs("button",{type:"button",className:"mt-4 inline-flex items-center gap-1 text-xs text-muted-foreground underline",onClick:()=>h("email"),children:[t.jsx(Te,{className:"h-3 w-3"}),e("auth.phone.use_email")]})]}):y==="code"?t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{ref:de,className:"flex justify-center",children:t.jsx(Be,{maxLength:6,value:G,onChange:a=>{w(a),a.length===6&&!f&&ue(a)},disabled:f,autoFocus:!0,children:t.jsxs(Ue,{children:[t.jsx(ae,{index:0}),t.jsx(ae,{index:1}),t.jsx(ae,{index:2}),t.jsx(ae,{index:3}),t.jsx(ae,{index:4}),t.jsx(ae,{index:5})]})})}),oe&&t.jsx("p",{role:"alert",className:"rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs text-destructive",children:oe}),t.jsx(q,{type:"button",className:"w-full",onClick:()=>ue(G),disabled:f||G.length!==6,children:e(f?"auth.code.verifying":"auth.code.verify")}),t.jsx("p",{className:"text-center text-[11px] text-muted-foreground",children:e("auth.code.expires")}),t.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[t.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 underline",onClick:()=>{j("phone"),w("")},children:[t.jsx(Te,{className:"h-3 w-3"}),e("auth.code.use_diff_number")]}),t.jsx("button",{type:"button",className:"underline disabled:no-underline disabled:text-muted-foreground/60",disabled:O>0||F,onClick:()=>z(),children:O>0?e("auth.code.resend_in",{seconds:O}):e(F?"auth.code.sending":"auth.code.resend")})]})]}):t.jsxs("form",{onSubmit:ye,className:"space-y-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(je,{htmlFor:"first-name",children:e("auth_name.first_label")}),t.jsx(Se,{id:"first-name",type:"text",autoComplete:"given-name",autoFocus:!0,maxLength:60,placeholder:e("auth_name.first_label"),value:ie,onChange:a=>{ge(a.target.value),ee&&ce(null)},"aria-invalid":ee?!0:void 0})]}),ee&&t.jsx("p",{role:"alert",className:"rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs text-destructive",children:ee}),t.jsx(q,{type:"submit",className:"w-full",disabled:le||ie.trim().length<1,children:e(le?"auth_name.saving":"auth_name.continue")}),t.jsx("button",{type:"button",className:"mx-auto block text-xs text-muted-foreground underline",onClick:i,disabled:le,children:e("auth_name.skip")})]})})]})]})}export{Xt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.