PageSourceSearch

https://ninjapipe.app/static/js/86515.6bba7ca8.chunk.js

js ninjapipe.app collected 2026-10-04 01:52:16 UTC 33,298 bytes, 8 lines download raw bytes

1"use strict";(globalThis.webpackChunkninjapipe=globalThis.webpackChunkninjapipe||[]).push([[86515],{86515(Eo,ye,r){r.r(ye),r.d(ye,{default:()=>_o});var u=r(51477),Ie=r(40259),z=r(50388),_e=r(23970),F=r(6227),ke=r(17573),ce=r(82380),N=r(9995),B=r(42727),Ce=r(95910),Lo=r(86052),Io=r(9981),eo=r(4404),Re=r(93078),i=r(67763),oo=r(59339),_=r(75447),Ro=r(72588);async function to(w,S){const e=String(w||"").trim().toLowerCase(),b=String(S||"").trim().toLowerCase();if(!e||!b||typeof window>"u"||!(0,Ro.p)(window.location.hostname))return!1;try{if((await(0,_.Bk)({workspaceSlug:b})).region!=="eu"||await(0,i.SM)())return!1;const c=await(0,_.ku)(e);return(0,_._S)(c.regions)}catch{return!1}}var fe=r(97151),Mo=r(63338),jo=r(5341),no=r(88715),Wo=r(65865),I=r(42827),Me=r(3386),je=r(37102),Z=r(77863),Ho=r(74549),Oo=r(24749),To=r(6557),Uo=r(23265),ro=r(77082),pe=r(13154),io=r(31623),ao=r(78378),so=r(33643),Do=r(39889),we=r(51614),No=r(24528),C=r(23302),be=r(19946),Bo=r(45375),Go=r(97010),T=r(87241);const We="np-oauth-region-handoff-attempted";function lo(){let w=arguments.length>0&&arguments[0]!==void 0?arguments[0]:typeof window<"u"?window.location.search:"";const S=window.location.hostname,e=new URLSearchParams(w),b=e.get("workspace");let U=typeof window<"u"?`${window.location.origin}${window.location.pathname}`:"/login";const c=S==="localhost"||S==="127.0.0.1"||S.startsWith("localhost:")||S.startsWith("127.0.0.1:"),K=S.includes("ninjapipe.app"),D=new URLSearchParams;if(c&&!K&&b){const Ae=(0,C.Vt)(b);Ae&&D.set("workspace",Ae)}const se=e.get("invitation"),de=e.get("workspaceName"),h=e.get("email");
1se&&D.set("invitation",se),de&&D.set("workspaceName",de),h&&D.set("email",h);const X=(0,be.Q)(w);X&&D.set("oauth_return",X);const ee=(0,T.Q4)(w);return ee&&D.set("redirect",ee),D.toString()&&(U+=`?${D.toString()}`),U}async function zo(){var w;let S=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};await(0,fe.H)({email:((w=S.email)===null||w===void 0?void 0:w.trim())||void 0,workspaceSlug:S.workspaceSlug||void 0,preferredRegion:S.preferredRegion}),(0,_.g)((0,i.d5)());const e=lo(),{error:b}=await i.ND.auth.signInWithOAuth({provider:"google",options:{redirectTo:e,queryParams:{access_type:"offline",prompt:"consent"}}});if(b)throw b}async function Fo(w,S){const e=String(S||"").trim().toLowerCase(),b=w==="eu"?"eu":"au";try{if(sessionStorage.getItem(We)===b)return{retried:!1};sessionStorage.setItem(We,b)}catch{}await(0,i.hG)({region:b,email:e||void 0}),(0,_.g)(b);const U=lo(),{error:c}=await i.ND.auth.signInWithOAuth({provider:"google",options:{redirectTo:U,queryParams:{access_type:"offline",prompt:"consent"}}});if(c)throw c;return{retried:!0}}function Ko(){try{sessionStorage.removeItem(We)}catch{}}var He=r(85067),a=r(70481);const co=u.memo(()=>{const{t:w}=(0,Re.Bd)();return(0,a.jsx)(z.A,{component:"span","aria-hidden":!0,sx:{position:"absolute",top:-9,right:10,zIndex:1,px:1,py:.25,borderRadius:"10px",bgcolor:"common.black",color:"common.white",fontSize:10,fontWeight:700,lineHeight:1.4,letterSpacing:.3,textTransform:"uppercase",boxShadow:"0 1px 4px rgba(0, 0, 0, 0.18)",pointerEvents:"none",whiteSpace:"nowrap"},children:w("login.lastUsed")})});co.displayName="LastUsedLoginBadge";const uo=co;var Vo=r(69889),Qo=r(70354);const Xo=[{value:"au",labelKey:"login.signInRegion.international"},{value:"eu",labelKey:"login.signInRegion.europe"}];function Yo(w){let{value:S,onChange:e,disabled:b=!1}=w;const{t:U}=(0,Re.Bd)(),c=(0,ao.e)(),K=(0,so.rn)(),D=u.useMemo(()=>(0,io.jM)(c?"dark":"light",K),[c,K]),se=u.useMemo(()=>Xo.map(h=>({value:h.value,label:U(h.labelKey)})),[U]),de=h=>{var X;const ee=h==null||(X=h.target)===null||X===void 0?void 0:X.value;(ee==="au"||ee==="eu")&&e(ee)};return(0,a.jsxs)(z.A,{sx:{mt:2,pt:2,borderTop:`1px solid ${D.border.secondary}`},children:[(0,a.jsx)(F.A,{sx:{color:D.text.secondary,fontSize:12,fontWeight:500,mb:1,textAlign:"center",lineHeight:1.45},children:U("login.signInRegion.hint")}),(0,a.jsx)(Qo.A,{label:U("login.signInRegion.label"),value:S,onChange:de,options:se,disabled:b,fullWidth:!0,size:"small",mb:0,triggerMinHeightPx:36,labelVariant:"legacy",primaryColor:K,isDark:c,icon:Vo.UnE,getOptionLabel:h=>h.label,getOptionValue:h=>h.value})]})}var te=r(19277);const Oe="np-login-oauth-code-lock";function Te(w){let S=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const e=w?.slug;if(e)return(0,C.Vt)(e);const b=new URLSearchParams(S).get("workspace");return b?(0,C.Vt)(b):(0,Me.WJ)()}async function Zo(w){let S=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const e=Te(w,S);return e||await(0,Me.xo)().catch(()=>null)||null}function go(){try{return sessionStorage.getItem(Oe)}catch{return null}}function Jo(){if(typeof window>"u")return!1;const w=new URLSearchParams(window.location.search);if((w.get("code")||"").trim()||(w.get("workspace_session_redeem")||"").trim())return!0;const S=new URLSearchParams((window.location.hash||"").replace(/^#/,""));return!!(S.get("access_token")&&!S.get("error"))}function $o(w){try{return sessionStorage.setItem(Oe,w),!0}catch{return!1}}const mo=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;function Ue(w,S,e){w(e),S(!0),setTimeout(()=>S(!1),600)}function qo(){try{sessionStorage.removeItem(Oe)}catch{}}function _o(){const{user:w,userId:S}=(0,Ie.A)(),{t:e}=(0,Re.Bd)(),b=(0,ao.e)(),U=(0,so.rn)(),c=u.useMemo(()=>(0,io.jM)(b?"dark":"light",U),[b,U]),K=(0,no.zy)(),D=(0,Uo.B)(K.pathname,null),[se,de]=u.useState(!1),[h,X]=u.useState({email:"",password:""}),[ee,Ae]=u.useState(!1),[Pe,Ee]=u.useState(!1),[ve,W]=u.useState(Jo),[ho,v]=u.useState(""),[et,g]=u.useState(!1),[d,ue]=u.useState(null),[ot,fo]=u.useState(!1),[tt,J]=u.useState(!1),[ne,nt]=u.useState(null),[rt,De]=u.useState(!1),[$,xe]=u.useState(jo.uQ),Se=u.useRef(!1),V=!d&&!(0,I.d8)();u.useEffect(()=>{if(!V)return;const t=new URLSearchParams(window.location.search).get("region");if(t==="eu"||t==="au"){Se.current=!0,xe(t);return}let n=!1;return(async()=>{try{const l=await(0,_.Bm)();if(n||Se.current)return;
1(l.region==="eu"||l.region==="au")&&xe(l.region)}catch{}})(),()=>{n=!0}},[V]),u.useEffect(()=>{if(!V)return;const o=h.email.trim().toLowerCase();if(!mo.test(o))return;let t=!1;return(async()=>{const n=await(0,_.ku)(o);if(t)return;const l=(0,fe._)(n);!l||l===$||(Se.current=!0,xe(l))})(),()=>{t=!0}},[V,h.email,$]),u.useEffect(()=>{if(!V)return;const o=h.email.trim().toLowerCase();(0,i.hG)({region:$,email:o||void 0})},[V,$,h.email]);const it=u.useCallback(async o=>{if(o!=="au"&&o!=="eu")return;Se.current=!0,xe(o);const t=h.email.trim().toLowerCase();await(0,i.hG)({region:o,email:t||void 0})},[h.email]),Ne=u.useMemo(()=>(0,te.x9)({workspaceSlug:d?.slug}),[d?.slug,K.search]),[po,wo]=u.useState(()=>(0,te.h7)(Ne)),R=(0,no.Zp)(),ge=u.useRef(!1);u.useEffect(()=>{wo((0,te.h7)(Ne))},[Ne]);const vo=u.useCallback(o=>{(0,te.PV)(o,{workspaceSlug:d?.slug}),wo(o)},[d?.slug]);u.useEffect(()=>{ge.current=Pe||ve},[Pe,ve]);const at=u.useMemo(()=>{if(d){const o=(0,ro.V1)(d);if(o){const t=(0,ro.Nk)(o,d);if(t)return t}return null}return D},[d,D]);u.useEffect(()=>{const o=(0,je.VM)(),t=(0,je.km)();if(o){const n={source:"login_page"};t!=null&&t.code?n.affiliate_link_code=t.code:t!=null&&t.id&&(n.affiliate_link_id=t.id),(0,je.h8)(o,n).catch(()=>{})}},[]),u.useEffect(()=>{const o=new URLSearchParams(window.location.search),t=o.get("email");if(t&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(decodeURIComponent(t))){const s=decodeURIComponent(t).trim();X(p=>({...p,email:s})),Ae(!0),(0,i.hG)({email:s}).catch(()=>{})}if(o.get("invitation")==="1"){var l;const s=(l=o.get("workspaceName"))!==null&&l!==void 0?l:"";(async()=>{let k=!1;if(t)try{var M;const m=window.location.hostname==="localhost"||window.location.hostname.includes("localhost")?"http://localhost:3001":"https://ninjapipe.app",A=await(await fetch(`${m}/api/check-account-exists?email=${encodeURIComponent(t)}`)).json();k=!!(A!=null&&A.exists)}catch{}if(k)nt({workspaceName:s,hasAccount:!0});else{const m=(0,I.nR)(window.location.search);m.startsWith("http")?window.location.replace(m):R(m,{replace:!0})}})()}},[R]),u.useEffect(()=>{(async()=>{try{fo(!0);const t=window.location.hostname,n=new URLSearchParams(window.location.search),l=n.get("workspace"),s=n.get("email"),p=n.get("region"),k=p==="eu"||p==="au"?p:void 0;await(0,oo.d)({workspaceSlug:l,email:s?decodeURIComponent(s).trim():void 0,region:k});const M=(0,I.uc)();let m=null;const j=t==="localhost"||t==="127.0.0.1"||t.startsWith("localhost:")||t.startsWith("127.0.0.1:"),A=t.includes("ninjapipe.app");if(j&&!A&&l)m=(0,C.Vt)(l);else if(M&&A){const y=t.split(".");if(y.length>=3&&t.includes("ninjapipe.app")){const E=y[0];m=(0,C.Vt)(E)}}else if((0,I.d8)()){const y=await(0,Mo.m)(t);if(y){await(0,i.hG)({region:y.region,workspaceSlug:y.slug});const{data:E,error:Q}=await i.ND.from("workspaces").select("id, name, slug, brand_logo_url, brand_color, appbar_logo_url, appbar_logo_light_url, avatar_url, settings, updated_at").eq("id",y.workspaceId).eq("is_active",!0).maybeSingle();ue(!Q&&E?E:null)}else ue(null);return}if(m){await(0,i.hG)({workspaceSlug:m}).catch(()=>{});const{data:y,error:E}=await i.ND.from("workspaces").select("id, name, slug, brand_logo_url, brand_color, appbar_logo_url, appbar_logo_light_url, avatar_url, settings, updated_at").eq("slug",m).eq("is_active",!0).single();E||!y?(console.error("Workspace not found:",E),ue(null)):ue(y)}else ue(null)}catch(t){console.error("Error fetching workspace data:",t),ue(null)}finally{fo(!1)}})()},[]),u.useEffect(()=>{let o=!1;return(async()=>{if(o||await(0,He.oW)(R,e))return;const n=new URLSearchParams(window.location.search),l=n.get("email"),s=l?decodeURIComponent(l).trim():"",p=n.get("region"),k=p==="eu"||p==="au"?p:void 0,M=await(0,oo.d)({email:s||void 0,workspaceSlug:n.get("workspace"),region:k}),m=new URLSearchParams((window.location.hash||"").replace(/^#/,"")),j=n.get("code"),A=m.get("code"),y=(j||A||"").trim(),E=n.get("error")||m.get("error"),Q=n.get("error_description")||m.get("error_description"),f=(0,T.Q4)(window.location.search),G=function(){let H=arguments.length>0&&arguments[0]!==void 0?arguments[0]:(0,be.Q)(window.location.search);const P=new URLSearchParams;H&&P.set("oauth_return",H),f&&P.set("redirect",f);const O=P.toString();window.history.replaceState({},document.title,window.location.pathname+(O?`?${O}`:""))};if(y){W(!0);let H=!1;if(go()===y){W(!1);return}H=$o(y);const P=(0,be.Q)(window.location.search);try{var ie,me;let O=(ie=(me=(await i.ND.auth.getSession()).data)===null||me===void 0?void 0:me.session)!==null&&ie!==void 0?ie:null,x=null;if(!O){var Fe,Ke,Ve;const q=await i.ND.auth.exchangeCodeForSession(y);O=(Fe=(Ke=q.data)===null||Ke===void 0?void 0:Ke.session)!==null&&Fe!==void 0?Fe:null,x=(Ve=q.error)!==null&&Ve!==void 0?Ve:null}if(!O){var Qe,Xe;O=(Qe=(Xe=(await i.ND.auth.getSession()).data)===null||Xe===void 0?void 0:Xe.session)!==null&&Qe!==void 0?Qe:null}if(O)G(P),(0,I.Md)(window.location.search)&&(0,Z.fl)(),await So(O);else{var Ye,Ze;x&&console.error("[LoginPage] OAuth code exchange failed:",x);const q=((Ye=x)===null||Ye===void 0?void 0:Ye.name)==="AuthPKCECodeVerifierMissingError"||((Ze=x)===null||Ze===void 0?void 0:Ze.message)&&String(x.message).toLowerCase().includes("code verifier");v(e(q?"login.errors.pkceWrongRedirectOrigin":"login.errors.authenticationCancelled")),g(!0),setTimeout(()=>g(!1),600),G()}}finally{H&&qo(),W(!1)}return}if(E){const H=n.get("error_code"),P={error:E,error_code:H,error_description:Q,search:window.location.search};console.error("[LoginPage] SSO/auth error from redirect:",P),v(Q?decodeURIComponent(Q.replace(/\+/g," ")):e("login.errors.authenticationCancelled")),g(!0),setTimeout(()=>g(!1),600),W(!1),G();return}const Je=n.get(C.Hq);if(Je===C.F2.PENDING||Je===C.F2.NO_ACCESS){const H=new URLSearchParams(n);H.delete(C.Hq);const P=H.toString();window.history.replaceState({},document.title,window.location.pathname+(P?`?${P}`:""));const O=Je===C.F2.PENDING;J(O),v(e(O?"login.errors.pendingInvitation":"login.errors.workspaceAccess")),g(!0),setTimeout(()=>g(!1),600),await(0,i.o8)(),W(!1);return}const Le=(window.location.hash||"").substring(1),Co=m.get("access_token"),bo=m.get("error"),mt=m.get("error_description"),{data:{session:ae}}=await i.ND.auth.getSession();if(ae){var $e;const H=await(0,we.u)(ae);if(!H.ok){window.location.assign(H.redirectTo);return}const P=(($e=ae.user)===null||$e===void 0?void 0:$e.email)||s;if(P&&M.workspaceSlug){if(await to(P,M.workspaceSlug)){De(!0),h.email||X(Y=>({...Y,email:P})),await(0,i.hG)({workspaceSlug:M.workspaceSlug,email:P}).catch(()=>{}),W(!1);return}const{hasAccess:q,workspace:L,hasPendingInvitation:oe}=await(0,C.H6)(M.workspaceSlug,ae.user.id,P);
1if(q&&L){if((0,Z.OR)({id:L.id,slug:M.workspaceSlug,name:L.name,avatar_url:L.avatar_url,appbar_logo_url:L.appbar_logo_url,appbar_logo_light_url:L.appbar_logo_light_url,brand_color:L.brand_color,brand_logo_url:L.brand_logo_url,data_region:(0,i.d5)()}),window.dispatchEvent(new CustomEvent("workspaceUpdated")),f){(0,T.C9)(),R(f,{replace:!0});return}(0,T.C9)(),R("/dashboard",{replace:!0});return}if((0,I.d8)()||(0,I.uc)()){await(0,i.o8)(),J(!!oe),v(e(oe?"login.errors.pendingInvitation":"login.errors.workspaceAccess")),g(!0),setTimeout(()=>g(!1),600),W(!1);return}}const O=w;if(O){try{const x=O;if((0,I.uc)()){const L=()=>{const le=(0,I.Jj)(),he=(0,T.u5)("/workspaces",f);le.startsWith("http")?window.location.href=`${le.replace(/\/$/,"")}${he}`:R(he,{replace:!0})},oe=window.location.hostname,Y=oe.split(".");if(Y.length>=3&&oe.includes("ninjapipe.app")){const le=Y[0],he=(0,C.Vt)(le);if(he){const{hasAccess:ht,workspace:Ao,hasPendingInvitation:Po}=await(0,C.H6)(he,x.id,x.email);if(ht&&Ao){if((0,Z.OR)(Ao),window.dispatchEvent(new CustomEvent("workspaceUpdated")),Le&&window.history.replaceState({},document.title,window.location.pathname+window.location.search),f){(0,T.C9)(),R(f,{replace:!0});return}(0,T.C9)(),R("/dashboard",{replace:!0})}else{console.error("User does not have access to workspace subdomain:",{workspaceSlug:he,userId:x.id,userEmail:x.email}),await(0,i.o8)(),J(!!Po),v(e(Po?"login.errors.pendingInvitation":"login.errors.workspaceAccess")),g(!0),setTimeout(()=>g(!1),600),Le&&window.history.replaceState({},document.title,window.location.pathname+window.location.search),W(!1);return}}else L()}else L()}else if((0,I.d8)()){const L=await(0,Me.xo)();if(L){const{hasAccess:oe,workspace:Y,hasPendingInvitation:le}=await(0,C.H6)(L,x.id,x.email);if(oe&&Y){if((0,Z.OR)(Y),window.dispatchEvent(new CustomEvent("workspaceUpdated")),Le&&window.history.replaceState({},document.title,window.location.pathname+window.location.search),f){(0,T.C9)(),R(f,{replace:!0});return}(0,T.C9)(),R("/dashboard",{replace:!0});return}console.error("User does not have access to workspace custom domain:",{workspaceSlug:L,userId:x.id,userEmail:x.email}),await(0,i.o8)(),J(!!le),v(e(le?"login.errors.pendingInvitation":"login.errors.workspaceAccess")),g(!0),setTimeout(()=>g(!1),600),Le&&window.history.replaceState({},document.title,window.location.pathname+window.location.search),W(!1);return}await(0,i.o8)(),v(e("login.errors.workspaceAccess")),g(!0),setTimeout(()=>g(!1),600),W(!1);return}else{const L=(0,be.Q)(window.location.search);if(L){(0,T.C9)(),R(L,{replace:!0});return}(0,I.Md)(window.location.search)&&(0,Z.fl)();const oe=window.location.hostname,Y=(0,Z.gy)();if((0,I.Ze)(oe)&&Y!==null&&Y!==void 0&&Y.id){if(f){(0,T.C9)(),R(f,{replace:!0});return}(0,T.C9)(),R("/dashboard",{replace:!0});return}R((0,T.u5)("/workspaces",f),{replace:!0})}}catch(x){if(console.error("Error in initializeAuth:",x),(0,I.d8)()){const q=(0,I.Jj)(),L=(0,T.u5)("/workspaces",f);q.startsWith("http")?window.location.href=`${q.replace(/\/$/,"")}${L}`:R(L,{replace:!0})}else R((0,T.u5)("/workspaces",f),{replace:!0})}return}if(Co&&ae&&ae.user){console.log("OAuth callback detected, processing authentication..."),window.history.replaceState({},document.title,window.location.pathname+window.location.search);const x=await(0,we.u)(ae);if(!x.ok){window.location.assign(x.redirectTo);return}await So(ae);return}}if(bo){console.error("OAuth error:",bo,mt),v(e("login.errors.authenticationCancelled")),g(!0),setTimeout(()=>g(!1),600),W(!1),G();return}if(!Co){if(go()){W(!0);return}let H="";try{var qe;const x=w;H=x&&((qe=JSON.parse(x))===null||qe===void 0?void 0:qe.email)||""}catch{}const P=s||H;if(P&&M.workspaceSlug?await to(P,M.workspaceSlug):!1)De(!0),P&&!h.email&&X(x=>({...x,email:P})),await(0,i.hG)({workspaceSlug:M.workspaceSlug,email:P}).catch(()=>{});else{if(De(!1),o||ge.current)return;const{data:{session:x}}=await i.ND.auth.getSession();if(o||ge.current||x!=null&&x.user)return;await(0,i.o8)()}}})(),()=>{o=!0}},[R,e]);const st=()=>de(o=>!o),lt=o=>{o.preventDefault()},xo=o=>{X(t=>({...t,[o.target.name]:o.target.value}))},Be=u.useCallback(async function(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:h.email).trim().toLowerCase(),n=Te(d,K.search);if(!(!t&&!n))try{await(0,fe.H)({email:t||void 0,workspaceSlug:n||void 0,preferredRegion:V?$:void 0})}catch(l){console.warn("[LoginPage] prepareLoginSupabaseRegion failed:",l)}},[h.email,d?.slug,K.search,V,$]),ct=()=>{const o=h.email.trim();
1/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o)&&Be(o)};u.useEffect(()=>{Be(h.email)},[Be]);const ft=async(o,t)=>{try{var n;console.log("[MEMBERSHIP CHECK] Starting check:",{email:o,workspaceSlug:t});const l=(0,C.Vt)(t);if(!l)return console.log("[MEMBERSHIP CHECK] \u274C Invalid workspace slug:",t),{isMember:!1,workspace:null};const{data:s,error:p}=await i.ND.from("workspaces").select("id, name, slug").eq("slug",l).eq("is_active",!0).single();if(p||!s)return console.log("[MEMBERSHIP CHECK] \u274C Workspace not found:",{error:p,slug:l}),{isMember:!1,workspace:null};console.log("[MEMBERSHIP CHECK] \u2705 Workspace found:",{id:s.id,name:s.name,slug:s.slug});const k=o.trim(),M=k.toLowerCase(),{data:m,error:j}=await i.ND.from("workspace_accounts").select(`
2          id,
3          workspace_id,
4          role,
5          is_active,
6          account_id,
7          accounts!workspace_accounts_account_id_fkey(id, email)
8        `).eq("workspace_id",s.id).eq("is_active",!0).eq("is_deleted",!1).limit(200);if(console.log("[MEMBERSHIP CHECK] Memberships query:",{count:m?.length,error:j}),j||!m||m.length===0)return console.log("[MEMBERSHIP CHECK] \u274C No memberships found or error:",j),{isMember:!1,workspace:s};const A=m.find(y=>{if(!y.accounts||!y.accounts.email)return console.log("[MEMBERSHIP CHECK] Membership missing accounts data:",{account_id:y.account_id,hasAccounts:!!y.accounts}),!1;const E=y.accounts.email.trim(),Q=(E===k||E.toLowerCase()===M)&&y.is_active;return console.log("[MEMBERSHIP CHECK] Checking membership:",{accountEmail:E,trimmedEmail:k,emailLower:M,matches:Q,is_active:y.is_active}),Q});return A?(console.log("[MEMBERSHIP CHECK] \u2705 Membership found:",{membershipId:A.id,role:A.role,accountId:A.account_id,accountEmail:(n=A.accounts)===null||n===void 0?void 0:n.email}),A.is_active?(console.log("[MEMBERSHIP CHECK] \u2705 Membership verified - user is a member:",{membershipId:A.id,role:A.role}),{isMember:!0,workspace:s}):(console.log("[MEMBERSHIP CHECK] \u274C Membership is inactive:",A),{isMember:!1,workspace:s})):(console.log("[MEMBERSHIP CHECK] \u274C No membership found for email:",k),{isMember:!1,workspace:s})}catch(l){return console.log("[MEMBERSHIP CHECK] \u274C Exception:",{error:l.message,stack:l.stack}),{isMember:!1,workspace:null}}},dt=async()=>{vo(te.YK.GOOGLE),ge.current=!0,W(!0),v(""),J(!1);try{var o;if((0,I.d8)()){const p=await(0,Bo.Sj)({returnUrl:window.location.href,flow:"login"}),k=await(0,He.LG)(p);if(!k.ok){try{await i.ND.auth.signOut()}catch{}(0,Z.ib)(),await(0,i.o8)(),v((0,He.Ib)(k.reason,k,e)),g(!0),setTimeout(()=>g(!1),600);return}const M=await(0,Go.u)(k.session,R,e);if(!M.ok){try{await i.ND.auth.signOut()}catch{}(0,Z.ib)(),await(0,i.o8)(),J(M.pendingInvitation),M.pendingInvitation?v(e("login.errors.pendingInvitation")):v(e("login.errors.workspaceAccess")),g(!0),setTimeout(()=>g(!1),600)}return}const t=new URLSearchParams(window.location.search),n=t.get("workspace"),l=h.email.trim()||((o=t.get("email"))===null||o===void 0?void 0:o.trim())||"",s=d?.slug||(n?(0,C.Vt)(n):null)||void 0;!s&&(0,I.Md)(window.location.search)&&(0,Z.fl)(),await zo({email:l||void 0,workspaceSlug:s,preferredRegion:V?$:void 0})}catch(t){console.error("Google OAuth error:",t);const n=t?.message;let l;n==="popup_blocked"?l=e("login.errors.popupBlocked"):(0,I.d8)()?l=e("login.errors.sessionHandoffFailed"):l=(0,pe.Z)(t,e,"login"),v(l),g(!0),setTimeout(()=>g(!1),600)}finally{ge.current=!1,W(!1)}},So=async o=>{try{var t;console.log("Processing OAuth success for user:",o.user.email),W(!0);const n=await(0,we.u)(o,{oauthHandoff:!0});if(!n.ok){if(n.oauthHandoffRegion){(await Fo(n.oauthHandoffRegion,n.email)).retried||(v(e("login.errors.authenticationCancelled")),g(!0),setTimeout(()=>g(!1),600),W(!1));return}window.location.assign(n.redirectTo);return}Ko();const l=await Zo(d,K.search);await(0,i.hG)({email:((t=o.user.email)===null||t===void 0?void 0:t.trim())||void 0,workspaceSlug:l||void 0});const{isLegacyUser:s}=await(0,Do.W)(o),p=await(0,No.R)(o);if(!p.ok){try{await i.ND.auth.signOut()}catch{}(0,Z.ib)(),await(0,i.o8)(),J(p.pendingInvitation),p.pendingInvitation?v(e("login.errors.pendingInvitation")):v(e("login.errors.workspaceAccess")),g(!0),setTimeout(()=>g(!1),600),W(!1);return}await(0,C._A)({user:o.user,session:o},R,e,s)}catch(n){console.error("Error handling OAuth success:",n),v((0,pe.Z)(n,e,"login")),g(!0),setTimeout(()=>g(!1),600),W(!1)}},ut=async o=>{o.preventDefault(),vo(te.YK.PASSWORD),v(""),J(!1);const t=h.email.trim().toLowerCase(),n=h.password;if(!t){Ue(v,g,e("login.errors.emailRequired"));return}if(!mo.test(t)){Ue(v,g,e("login.errors.invalidEmail"));return}if(!n){Ue(v,g,e("login.errors.passwordRequired"));return}Ee(!0);try{var l;ge.current=!0,await i.uL,await(0,i.c)({markExplicit:!0});const s=Te(d,K.search),p=await(0,_.ku)(t),k=(0,fe._)(p);k&&V&&k!==$&&(Se.current=!0,xe(k)),await(0,fe.H)({email:t,workspaceSlug:s||void 0,preferredRegion:V?$:void 0});const M=(0,i.d5)();console.log("[LoginPage] sign-in region:",M,"host:",(0,i.FS)());let{data:m,error:j}=await i.ND.auth.signInWithPassword({email:t,password:n});if(j&&k){await(0,i.hG)({region:k,email:t});const f=await i.ND.auth.signInWithPassword({email:t,password:n});m=f.data,j=f.error}let A=!1;if(!j&&(l=m)!==null&&l!==void 0&&l.session){const f=await(0,we.u)(m.session);if(!f.ok){window.location.assign(f.redirectTo);return}}if(j){if(console.error("[LoginPage] signInWithPassword failed:",{region:(0,i.d5)(),host:(0,i.FS)(),message:j.message,status:j.status,code:j.code}),p.exists&&p.region==="eu"&&!(0,_._S)(p.regions)){v((0,pe.Z)(j,e,"login")),g(!0),setTimeout(()=>g(!1),600);return}console.log("Supabase login failed, attempting legacy migration...",{message:j.message,status:j.status});try{await(0,i.hG)({region:"au",email:h.email.trim()});const f=await Wo.p.migrateAndSignIn(h.email,h.password);if(f.migrated)console.log("\u2705 Legacy account successfully migrated and signed in"),A=!0,m={user:f.user,session:f.session};else if(f.session)console.log("\u2705 Existing user signed in"),A=!0,m={user:f.user,session:f.session};else throw new Error("Migration completed but no session returned");await i.ND.auth.setSession({access_token:m.session.access_token,refresh_token:m.session.refresh_token});const G=await(0,we.u)(m.session);if(!G.ok){window.location.assign(G.redirectTo);return}}catch(f){console.error("Legacy migration failed:",f);const G=(0,pe.Z)(j,e,"login");throw new Error(G)}}const y=(0,I.uc)();let E=null;const Q=window.location.hostname;if(y){const f=Q.split(".");if(f.length>=3&&Q.includes("ninjapipe.app")){const G=f[0];if(E=(0,C.Vt)(G),E){const{hasAccess:ie,hasPendingInvitation:me}=await(0,C.H6)(E,m.user.id,m.user.email);if(!ie){await i.ND.auth.signOut(),J(me),v(e(me?"login.errors.pendingInvitation":"login.errors.workspaceAccess")),g(!0),setTimeout(()=>g(!1),600),Ee(!1);return}}}}else if((0,I.d8)()){const{data:f}=await i.ND.from("workspaces").select("slug").ilike("custom_domain",Q.toLowerCase()).eq("domain_verified",!0).eq("is_active",!0).maybeSingle();if(f!=null&&f.slug&&(E=(0,C.Vt)(f.slug),E)){const{hasAccess:G,hasPendingInvitation:ie}=await(0,C.H6)(E,m.user.id,m.user.email);if(!G){await i.ND.auth.signOut(),J(ie),v(e(ie?"login.errors.pendingInvitation":"login.errors.workspaceAccess")),g(!0),setTimeout(()=>g(!1),600),Ee(!1);return}}}await(0,C._A)(m,R,e,A)}catch(s){console.error("[LoginPage] sign-in failed:",s);const p=s?.message||"";s!=null&&s.code||s!=null&&s.status||s!=null&&s.__isAuthError?v((0,pe.Z)(s,e,"login")):p.includes("login.errors.")||p.startsWith("t(")?v(p):v(p||e("login.errors.default")),g(!0),setTimeout(()=>g(!1),600)}finally{Ee(!1)}},re=d?.brand_color||U,yo=u.useMemo(()=>({fontSize:12,fontWeight:500,mb:"4px"}),[]),gt=u.useMemo(()=>({outline:`2px solid ${re}`,outlineOffset:2}),[re]),ko=po===te.YK.PASSWORD,Ge=po===te.YK.GOOGLE,ze=Pe||ve;return ot?(0,a.jsx)(To.A,{logoSrc:at}):(0,a.jsxs)(z.A,{sx:{minHeight:"100vh",width:"100%",bgcolor:c.background.primary,display:"flex",flexDirection:"column",position:"relative",overflow:"hidden",boxSizing:"border-box"},children:[(0,a.jsx)(z.A,{sx:{position:"absolute",top:{xs:16,md:24},left:{xs:16,md:24},zIndex:10},children:(0,a.jsx)(Ho.A,{})}),(0,a.jsxs)(z.A,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",px:{xs:2,sm:3},py:{xs:3,md:4},overflow:"auto",boxSizing:"border-box"},children:[(0,a.jsx)(z.A,{sx:{display:"flex",justifyContent:"center",mb:{xs:2.5,md:3},mt:{xs:5,md:0},flexShrink:0},children:(0,a.jsx)("img",{src:d?.brand_logo_url||"/branding/ninjapipe-logo-fullwhite.png",alt:d?.name||"NinjaPipe",style:{height:d?48:32,objectFit:"contain",maxWidth:"100%"},onError:o=>{o.target.src!==`${window.location.origin}/branding/ninjapipe-logo-fullwhite.png`&&(o.target.src="/branding/ninjapipe-logo-fullwhite.png")}})}),(0,a.jsxs)(_e.A,{elevation:0,sx:{width:"100%",maxWidth:480,bgcolor:c.background.secondary,border:`1px solid ${c.border.primary}`,borderRadius:3,boxShadow:b?"0 24px 64px rgba(0, 0, 0, 0.35)":"0 24px 64px rgba(0, 0, 0, 0.12)",p:{xs:2.5,sm:3.5},boxSizing:"border-box"},children:[(0,a.jsx)(F.A,{variant:"h5",sx:{fontWeight:800,color:c.text.primary,mb:ne?1.5:.75,textAlign:"center",letterSpacing:-.5,fontSize:{xs:22,sm:24},wordWrap:"break-word"},children:ne?e("login.invitationModal.title",{workspaceName:ne.workspaceName||"a workspace"}):d?e("login.workspaceTitle",{workspaceName:d.name||d.slug}):e("login.title")}),ne?(0,a.jsx)(F.A,{sx:{color:c.text.secondary,mb:2.5,fontSize:{xs:14,sm:15},fontWeight:500,textAlign:"center",lineHeight:1.5,wordWrap:"break-word"},children:ne.hasAccount?(0,a.jsxs)(a.Fragment,{children:[e("login.invitationModal.messageWithAccountBefore"),(0,a.jsx)(z.A,{component:"span",sx:{color:c.text.primary,fontWeight:500},children:h.email}),e("login.invitationModal.messageWithAccountAfter")]}):e("login.invitationModal.messageWithoutAccount")}
8):(0,a.jsx)(F.A,{sx:{color:c.text.secondary,mb:2.5,fontSize:{xs:14,sm:15},fontWeight:500,textAlign:"center",wordWrap:"break-word"},children:e(rt?"regionalSession.upgradeHint":d?"login.workspaceSubtitle":"login.subtitle")}),(0,a.jsx)("form",{style:{width:"100%",maxWidth:"100%",boxSizing:"border-box"},onSubmit:ut,children:(0,a.jsxs)(ke.A,{spacing:1.5,sx:{width:"100%",maxWidth:"100%"},children:[(0,a.jsx)(eo.A,{label:e("login.email"),name:"email",value:h.email,onChange:xo,onBlur:ct,placeholder:e("login.emailPlaceholder"),type:"email",required:!0,autoComplete:"email",disabled:ee,inputProps:{readOnly:ee},labelVariant:"legacy",labelSx:yo,size:"medium",mb:0,primaryColor:re,fullWidth:!0}),(0,a.jsx)(eo.A,{label:e("login.password"),name:"password",value:h.password,onChange:xo,placeholder:e("login.passwordPlaceholder"),type:se?"text":"password",required:!0,autoComplete:"current-password",labelVariant:"legacy",labelSx:yo,size:"medium",mb:0,primaryColor:re,fullWidth:!0,actionButton:(0,a.jsx)(ce.A,{"aria-label":"toggle password visibility",onClick:st,onMouseDown:lt,edge:"end",sx:{color:c.text.secondary,minWidth:44,minHeight:44},children:se?(0,a.jsx)(Lo.A,{}):(0,a.jsx)(Io.A,{})})}),(0,a.jsx)(z.A,{sx:{display:"flex",justifyContent:"flex-end",mt:-1},children:(0,a.jsx)("a",{href:`/forgot-password${window.location.search}`,style:{color:c.text.primary,textDecoration:"underline",fontWeight:500,fontSize:13,minHeight:44,display:"inline-flex",alignItems:"center"},children:e("login.forgotPassword")})}),(0,a.jsxs)(z.A,{sx:{position:"relative",width:"100%"},children:[ko&&(0,a.jsx)(uo,{}),(0,a.jsx)(Oo.A,{type:"submit",loading:Pe,disabled:ze,loadingText:e("login.loggingIn"),primaryColor:re,sx:{...ko?gt:{},animation:et?"shakeX 0.6s":"none","@keyframes shakeX":{"0%":{transform:"translateX(0)"},"10%, 30%, 50%, 70%, 90%":{transform:"translateX(-8px)"},"20%, 40%, 60%, 80%":{transform:"translateX(8px)"},"100%":{transform:"translateX(0)"}}},children:e("login.logIn")})]}),ho&&(0,a.jsxs)(z.A,{sx:{mt:1,mb:-2,textAlign:"center",px:{xs:1,sm:0}},children:[(0,a.jsx)(F.A,{sx:{color:c.status.error,fontWeight:600,fontSize:{xs:13,md:15}},children:ho}),tt&&(()=>{const o=new URLSearchParams;h.email&&o.set("email",h.email);const t=`/login?${o.toString()}`,n=typeof window<"u"?window.location.hostname:"",s=n==="localhost"||n.startsWith("localhost.")||n.endsWith(".localhost")||n==="127.0.0.1"||n.startsWith("127.0.0.1.")?"":"https://www.ninjapipe.app",p=s?`${s}${t}`:t;return(0,a.jsx)(F.A,{component:"div",sx:{mt:1.5,fontSize:{xs:13,md:15}},children:(0,a.jsx)("a",{href:p,style:{color:re,textDecoration:"underline",fontWeight:600},children:e("login.errors.acceptInvitationLink")})})})()]})]})}),(0,a.jsxs)(ke.A,{direction:"row",alignItems:"center",spacing:2,sx:{mb:1.5,mt:1.5},children:[(0,a.jsx)(N.A,{sx:{flex:1,borderColor:c.border.secondary}}),(0,a.jsx)(F.A,{sx:{color:c.text.secondary,fontWeight:500,fontSize:14},children:"or"}),(0,a.jsx)(N.A,{sx:{flex:1,borderColor:c.border.secondary}})]}),(0,a.jsxs)(z.A,{sx:{position:"relative",width:"100%"},children:[Ge&&(0,a.jsx)(uo,{}),(0,a.jsx)(B.A,{variant:"outlined",startIcon:ve?(0,a.jsx)(Ce.A,{size:18,sx:{color:c.text.secondary}}):(0,a.jsx)("img",{src:"/thirdparty/google.svg",alt:"Google",style:{width:20,height:20}}),onClick:dt,disabled:ze,sx:{bgcolor:c.background.primary,color:c.text.primary,borderColor:Ge?re:c.border.primary,borderRadius:2,borderWidth:Ge?2:1,minHeight:47,fontWeight:500,px:3,py:0,textTransform:"none",fontSize:13.5,boxShadow:"none",mb:2,"&:hover":{bgcolor:c.background.primary,borderColor:re,color:c.text.primary,boxShadow:"none"},"&.Mui-disabled":{bgcolor:c.background.primary,color:c.text.secondary,borderColor:c.border.primary,opacity:1,cursor:"not-allowed"}},fullWidth:!0,children:e(ve?"login.signingIn":"login.signInWithGoogle")})]}),(0,I.Md)(window.location.search)&&!(ne!=null&&ne.hasAccount)&&(0,a.jsxs)(F.A,{sx:{color:c.text.secondary,mt:2,textAlign:"center",fontSize:{xs:13,md:14}},children:[e("login.dontHaveAccount")," ",(0,a.jsx)("a",{href:`/signup${window.location.search}`,style:{color:c.text.primary,textDecoration:"underline",fontWeight:600},children:e("login.signUp")})]}),V&&(0,a.jsx)(Yo,{value:$,onChange:it,disabled:ze}),(0,a.jsxs)(F.A,{sx:{color:c.text.tertiary,mt:2,textAlign:"center",fontSize:{xs:11,sm:12},lineHeight:1.5},children:[e("login.termsText")," ",(0,a.jsx)("a",{href:"https://ninjapipe.com/terms",target:"_blank",rel:"noopener noreferrer",style:{color:c.text.tertiary,textDecoration:"none",borderBottom:`1px dotted ${c.text.tertiary}`},onMouseOver:o=>o.currentTarget.style.textDecoration="underline",onMouseOut:o=>o.currentTarget.style.textDecoration="none",children:e("login.termsOfService")})," ",e("login.and")," ",(0,a.jsx)("a",{href:"https://ninjapipe.com/privacy",target:"_blank",rel:"noopener noreferrer",style:{color:c.text.tertiary,textDecoration:"none",borderBottom:`1px dotted ${c.text.tertiary}`},onMouseOver:o=>o.currentTarget.style.textDecoration="underline",onMouseOut:o=>o.currentTarget.style.textDecoration="none",children:e("login.privacyPolicy")}),"."]})]})]})]})}},65865(Eo,ye,r){r.d(ye,{p:()=>Ie});class u{constructor(){this.apiUrl=`${window.location.origin}/api/legacy-migration`,this.migrationCache=new Map}async migrateAndSignIn(F,ke){const ce=`${F.toLowerCase()}`;if(this.migrationCache.has(ce)){const N=this.migrationCache.get(ce);if(N.timestamp>Date.now()-3e5)return N.data;this.migrationCache.delete(ce)}try{const N=await fetch(this.apiUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:F,password:ke})}),B=await N.json();if(!N.ok)throw new Error(B.message||`HTTP ${N.status}: ${N.statusText}`);if(!B.success)throw new Error(B.message||"Migration failed");const Ce={user:{id:B.data.user.id,email:B.data.user.email,created_at:B.data.user.created_at},session:{access_token:B.data.session.access_token,refresh_token:B.data.session.refresh_token,expires_at:B.data.session.expires_at},isNewUser:B.data.isNewUser,migrated:B.data.migrated};return this.migrationCache.set(ce,{data:Ce,timestamp:Date.now()}),Ce}catch(N){throw console.error("Legacy migration API call failed:",N),N}}clearCache(){this.migrationCache.clear()}getCacheStats(){return{size:this.migrationCache.size,entries:Array.from(this.migrationCache.keys())}}}const Ie=new u;var z=null}}]);

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.