1import{c as T,ab as O,r as x,j as e,a8 as C,M as R,z as E}from"./index-B2wrSxfc.js";import{I as A}from"./input-DyFncjo7.js";import{o as U,s as P,L as N}from"./label-fR-yehFa.js";import{s as y}from"./client-CCqjQxUl.js";import{S as M}from"./shield-check-DSMwWd2k.js";import{L as D}from"./lock-CBnsznBI.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const W=T("LogIn",[["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}],["polyline",{points:"10 17 15 12 10 7",key:"1ail0h"}],["line",{x1:"15",x2:"3",y1:"12",y2:"12",key:"v6grx8"}]]);var $={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"}},F="authorization_response",B="/~oauth/initiate",V=["https://oauth.lovable.app","https://lovable.dev"],H="lovable://oauth-callback",G="http://127.0.0.1/iframe-oauth/callback",K=500,q=12e4;function z(t){let r;const n=new Promise(o=>{r=o}),i=o=>{if(!t.some(u=>o.origin===u))return;const d=o.data;!d||typeof d!="object"||d.type===F&&r(d.response)},g=()=>{window.removeEventListener("message",i)};return window.addEventListener("message",i),{cleanup:g,messagePromise:n}}function X(t){const r=window.screenX!==0||window.screenY!==0||!t,n=r?window.outerWidth*.5:window.screen.width*.5,i=r?window.outerHeight*.5:window.screen.height*.5,g=r?window.screenX+(window.outerWidth-n)/2:(window.screen.width-n)/2,o=r?window.screenY+(window.outerHeight-i)/2:(window.screen.height-i)/2;return{width:n,height:i,left:g,top:o}}function I(t,r){return t.state!==r?{error:new Error("State is invalid")}:t.error?t.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(t.error_description??"Sign in failed")}:!t.access_token||!t.refresh_token?{error:new Error("No tokens received")}:{tokens:{access_token:t.access_token,refresh_token:t.refresh_token},error:null}}function Y(){const t=navigator.userAgent;return!!(/iPhone|iPad|iPod|Android/i.test(t)||/Macintosh/i.test(t)&&navigator.maxTouchPoints>1)}function J(){return typeof crypto<"u"&&crypto.getRandomValues?[...crypto.getRandomValues(new Uint8Array(16))].map(t=>t.toString(16).padStart(2,"0")).join(""):Math.random().toString(36).substring(2)+Date.now().toString(36)}function Q(t={}){const r=t.oauthBrokerUrl??B,n=t.supportedOAuthOrigins??V;async function i(g,o={}){let m=!1;try{m=window.self!==window.top}catch{m=!0}const d=navigator.userAgent,u=/LovableApp\//.test(d),w=!u&&/lovable/i.test(d),b=J();let s=o.redirect_uri??window.location.origin;u&&m?s=H:w&&m&&(s=G);const a=new URLSearchParams({...o.extraParams,provider:g,redirect_uri:s,state:b});if(!m)return window.location.href=`${r}?${a.toString()}`,{error:null,redirected:!0};!u&&!w&&a.set("response_mode","web_message");const l=`${r}?${a.toString()}`,f=w?[...n,window.location.origin]:n,{messagePromise:k,cleanup:_}=z(f);let p;if(Y())p=window.open(l,"_blank");else{const{width:c,height:v,left:h,top:S}=X(m);p=window.open(l,"oauth",`width=${c},height=${v},left=${h},top=${S}`)}if(!p&&(u||w)){let c;const v=new Promise((h,S)=>{c=setTimeout(()=>{S(new Error("OAuth timed out waiting for response"))},q)});try{const h=await Promise.race([k,v]);return I(h,b)}catch(h){return{error:h instanceof Error?h:new Error(String(h))}}finally{c&&clearTimeout(c),_()}}if(!p)return _(),{error:new Error("Popup was blocked")};let j;const L=new Promise((c,v)=>{j=setInterval(()=>{p.closed&&(clearInterval(j),v(new Error("Sign in was cancelled")))},K)});try{const c=await Promise.race([k,L]);return I(c,b)}catch(c){return{error:c instanceof Error?c:new Error(String(c))}}finally{clearInterval(j),_(),p==null||p.close()}}return{signInWithOAuth:i}}typeof window<"u"&&(window.__lovable_cloud_auth_js_version=$.version);function Z(t={}){return Q(t)}const ee=Z(),te={auth:{signInWithOAuth:async(t,r)=>{const n=await ee.signInWithOAuth(t,{...r,extraParams:{...r==null?void 0:r.extraParams}});if(n.redirected||n.error)return n;try{await y.auth.setSession(n.tokens)}catch(i){return{error:i instanceof Error?i:new Error(String(i))}}return n}}},re=U({email:P().trim().email({message:"Enter a valid email address"}).max(255),password:P().min(8,{message:"Password must be at least 8 characters"}).max(128)}),ce=()=>
6{const t=O(),[r,n]=x.useState("signin"),[i,g]=x.useState(""),[o,m]=x.useState(""),[d,u]=x.useState(!1);x.useEffect(()=>{document.title="Admin sign in â Spread The Magic",(document.head.querySelector('meta[name="robots"]')??document.head.appendChild(Object.assign(document.createElement("meta"),{name:"robots"}))).setAttribute("content","noindex, nofollow")},[]),x.useEffect(()=>{const{data:s}=y.auth.onAuthStateChange((a,l)=>{l&&t("/admin",{replace:!0})});return y.auth.getSession().then(({data:a})=>{a.session&&t("/admin",{replace:!0})}),()=>s.subscription.unsubscribe()},[t]);const w=async s=>{s.preventDefault();const a=re.safeParse({email:i,password:o});if(!a.success){E({title:"Check your details",description:a.error.issues[0].message,variant:"destructive"});return}u(!0);try{if(r==="signin"){const{error:l}=await y.auth.signInWithPassword({email:a.data.email,password:a.data.password});if(l)throw l}else{const{data:l,error:f}=await y.auth.signUp({email:a.data.email,password:a.data.password,options:{emailRedirectTo:`${window.location.origin}/admin`}});if(f)throw f;l.session||E({title:"Check your email",description:"Confirm your address, then sign in to request admin access."})}}catch(l){const f=l instanceof Error?l.message:"Something went wrong";E({title:r==="signin"?"Sign in failed":"Sign up failed",description:f.includes("Invalid login")?"Wrong email or password.":f,variant:"destructive"})}finally{u(!1)}},b=async()=>{u(!0);const s=await te.auth.signInWithOAuth("google",{redirect_uri:`${window.location.origin}/admin/login`});if(s.error){u(!1),E({title:"Google sign-in failed",description:s.error.message??"Please try again.",variant:"destructive"});return}s.redirected||t("/admin",{replace:!0})};return e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background px-4 py-16",children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute -top-40 left-1/2 h-96 w-96 -translate-x-1/2 rounded-full bg-magic-purple/25 blur-3xl"}),e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute -bottom-40 right-0 h-96 w-96 rounded-full bg-magic-pink/20 blur-3xl"}),e.jsxs("div",{className:"relative w-full max-w-md",children:[e.jsxs("div",{className:"mb-8 flex flex-col items-center gap-3 text-center",children:[e.jsx(C,{className:"text-2xl"}),e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-border bg-card/60 px-3 py-1 text-[11px] font-semibold uppercase tracking-[0.2em] text-muted-foreground backdrop-blur",children:[e.jsx(M,{className:"h-3.5 w-3.5 text-magic-pink"}),"Internal access only"]})]}),e.jsxs("div",{className:"relative overflow-hidden rounded-3xl border border-border/70 bg-card/60 p-7 backdrop-blur-xl",children:[e.jsx("div",{"aria-hidden":!0,className:"absolute inset-x-0 top-0 h-px bg-gradient-to-r from-transparent via-magic-purple/70 to-transparent"}),e.jsx("h1",{className:"font-display text-2xl font-bold text-foreground",children:r==="signin"?"Admin sign in":"Create admin account"}),e.jsx("p",{className:"mt-1.5 text-sm text-muted-foreground",children:r==="signin"?"Authorized team members only.":"Access is granted by an existing admin after signup."}),e.jsxs("form",{onSubmit:w,className:"mt-6 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(N,{htmlFor:"admin-email",children:"Work email"}),e.jsx(A,{id:"admin-email",type:"email",inputMode:"email",autoComplete:"email",placeholder:"[email protected]",value:i,onChange:s=>g(s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N,{htmlFor:"admin-password",children:"Password"}),e.jsx(A,{id:"admin-password",type:"password",autoComplete:r==="signin"?"current-password":"new-password",placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",value:o,onChange:s=>m(s.target.value)})]}),e.jsxs("button",{type:"submit",disabled:d,className:"group inline-flex w-full items-center justify-center gap-2 rounded-full bg-gradient-cta px-6 py-3 text-sm font-bold text-white shadow-[var(--shadow-cta)] transition-smooth hover:-translate-y-0.5 disabled:opacity-60",children:[e.jsx(W,{className:"h-4 w-4 transition-transform duration-300 group-hover:translate-x-0.5"}),d?"Workingâ¦":r==="signin"?"Sign in":"Create account"]})]}),e.jsxs("div",{className:"my-5 flex items-center gap-3",children:[e.jsx("span",{className:"h-px flex-1 bg-border"}),e.jsx("span",{className:"text-[11px] uppercase tracking-widest text-muted-foreground",children:"or"}),e.jsx("span",{className:"h-px flex-1 bg-border"})]}),e.jsxs("button",{type:"button",onClick:b,disabled:d,className:"inline-flex w-full items-center justify-center gap-2 rounded-full border border-border bg-background/60 px-6 py-3 text-sm font-semibold text-foreground transition-smooth hover:-translate-y-0.5 hover:border-magic-purple/60 disabled:opacity-60",children:[e.jsx(R,{className:"h-4 w-4 text-magic-pink"}),"Continue with Google"]}),e.jsx("button",{type:"button",onClick:()=>n(r==="signin"?"signup":"signin"),className:"mt-5 w-full text-center text-xs text-muted-foreground underline-offset-4 transition-colors hover:text-magic-pink hover:underline",children:r==="signin"?"Need an account? Sign up":"Already have an account? Sign in"})]}),e.jsxs("p",{className:"mt-6 flex items-center justify-center gap-2 text-center text-[11px] text-muted-foreground",children:[e.jsx(D,{className:"h-3 w-3"}),"Unlisted page · admin role required to view data"]})]})]})};export{ce 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.