1import{e as x,u as L,f as j,r as _,j as n}from"./index-wOwJRo7J.js";import{B as y}from"./button-DDKa5W7t.js";import{L as I,I as O}from"./label-DlZuYSEg.js";var R={version:"1.1.2"},U="authorization_response",C="/~oauth/initiate",N=["https://oauth.lovable.app","https://lovable.dev"],D="lovable://oauth-callback",M="http://127.0.0.1/iframe-oauth/callback",B=500,F=12e4;function W(e){let t;const r=new Promise(a=>{t=a}),o=a=>{if(!e.some(d=>a.origin===d))return;const l=a.data;!l||typeof l!="object"||l.type===U&&t(l.response)},u=()=>{window.removeEventListener("message",o)};return window.addEventListener("message",o),{cleanup:u,messagePromise:r}}function $(e){const t=window.screenX!==0||window.screenY!==0||!e,r=t?window.outerWidth*.5:window.screen.width*.5,o=t?window.outerHeight*.5:window.screen.height*.5,u=t?window.screenX+(window.outerWidth-r)/2:(window.screen.width-r)/2,a=t?window.screenY+(window.outerHeight-o)/2:(window.screen.height-o)/2;return{width:r,height:o,left:u,top:a}}function T(e,t){return e.state!==t?{error:new Error("State is invalid")}:e.error?e.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(e.error_description??"Sign in failed")}:!e.access_token||!e.refresh_token?{error:new Error("No tokens received")}:{tokens:{access_token:e.access_token,refresh_token:e.refresh_token},error:null}}function H(){const e=navigator.userAgent;return!!(/iPhone|iPad|iPod|Android/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1)}function V(){return typeof crypto<"u"&&crypto.getRandomValues?[...crypto.getRandomValues(new Uint8Array(16))].map(e=>e.toString(16).padStart(2,"0")).join(""):Math.random().toString(36).substring(2)+Date.now().toString(36)}function K(e={}){const t=e.oauthBrokerUrl??C,r=e.supportedOAuthOrigins??N;async function o(u,a={}){let c=!1;try{c=window.self!==window.top}catch{c=!0}const l=navigator.userAgent,d=/LovableApp\//.test(l),g=!d&&/lovable/i.test(l),f=V();let w=a.redirect_uri??window.location.origin;d&&c?w=D:g&&c&&(w=M);const E=new URLSearchParams({...a.extraParams,provider:u,redirect_uri:w,state:f});if(!c)return window.location.href=`${t}?${E.toString()}`,{error:null,redirected:!0};!d&&!g&&E.set("response_mode","web_message");const P=`${t}?${E.toString()}`,i=g?[...r,window.location.origin]:r,{messagePromise:m,cleanup:h}=W(i);let v;if(H())v=window.open(P,"_blank");else{const{width:s,height:b,left:p,top:A}=$(c);v=window.open(P,"oauth",`width=${s},height=${b},left=${p},top=${A}`)}if(!v&&(d||g)){let s;const b=new Promise((p,A)=>{s=setTimeout(()=>{A(new Error("OAuth timed out waiting for response"))},F)});try{const p=await Promise.race([m,b]);return T(p,f)}catch(p){return{error:p instanceof Error?p:new Error(String(p))}}finally{s&&clearTimeout(s),h()}}if(!v)return h(),{error:new Error("Popup was blocked")};let S;const k=new Promise((s,b)=>{S=setInterval(()=>{v.closed&&(clearInterval(S),b(new Error("Sign in was cancelled")))},B)});try{const s=await Promise.race([m,k]);return T(s,f)}catch(s){return{error:s instanceof Error?s:new Error(String(s))}}finally{clearInterval(S),h(),v?.close()}}return{signInWithOAuth:o}}typeof window<"u"&&(window.__lovable_cloud_auth_js_version=R.version);function G(e={}){return K(e)}const X=G(),Y={auth:{signInWithOAuth:async(e,t)=>
1{const r=await X.signInWithOAuth(e,{redirect_uri:t?.redirect_uri,extraParams:{...t?.extraParams}});if(r.redirected||r.error)return r;try{await x.auth.setSession(r.tokens)}catch(o){return{error:o instanceof Error?o:new Error(String(o))}}return r}}};function Q(){const e=L(),t=j.useSearch(),[r,o]=_.useState("signin"),[u,a]=_.useState(""),[c,l]=_.useState(""),[d,g]=_.useState(!1),[f,w]=_.useState(null);_.useEffect(()=>{x.auth.getUser().then(({data:m})=>{m.user&&e({to:t.redirect,replace:!0})});const{data:i}=x.auth.onAuthStateChange((m,h)=>{h?.user&&e({to:t.redirect,replace:!0})});return()=>i.subscription.unsubscribe()},[e,t.redirect]);const E=async i=>{i.preventDefault(),g(!0),w(null);const m=r==="signin"?x.auth.signInWithPassword({email:u,password:c}):x.auth.signUp({email:u,password:c,options:{emailRedirectTo:window.location.origin}}),{error:h}=await m;g(!1),h&&w(h.message)},P=async()=>{w(null);const i=await Y.auth.signInWithOAuth("google",{redirect_uri:window.location.origin});i.error&&w(i.error.message)};return n.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:n.jsxs("div",{className:"w-full max-w-sm rounded-2xl border border-border bg-card p-6 shadow-card",children:[n.jsx("h1",{className:"font-display text-2xl font-semibold",children:r==="signin"?"Admin sign in":"Create admin account"}),n.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"The first account on this site becomes the admin."}),n.jsx(y,{type:"button",variant:"outline",className:"mt-5 w-full",onClick:P,children:"Continue with Google"}),n.jsx("div",{className:"my-4 text-center text-xs uppercase tracking-wider text-muted-foreground",children:"or"}),n.jsxs("form",{onSubmit:E,className:"space-y-3",children:[n.jsxs("div",{children:[n.jsx(I,{htmlFor:"email",children:"Email"}),n.jsx(O,{id:"email",type:"email",required:!0,value:u,onChange:i=>a(i.target.value)})]}),n.jsxs("div",{children:[n.jsx(I,{htmlFor:"password",children:"Password"}),n.jsx(O,{id:"password",type:"password",required:!0,minLength:8,value:c,onChange:i=>l(i.target.value)})]}),f&&n.jsx("p",{className:"text-sm text-destructive",children:f}),n.jsx(y,{type:"submit",className:"w-full",disabled:d,children:d?"â¦":r==="signin"?"Sign in":"Sign up"})]}),n.jsx("button",{type:"button",onClick:()=>o(r==="signin"?"signup":"signin"),className:"mt-4 w-full text-sm text-muted-foreground hover:text-foreground",children:r==="signin"?"Need an account? Sign up":"Have an account? Sign in"})]})})}export{Q as component};
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.