PageSourceSearch

https://midnight-link.base44.app/static/AuthContext-BwFq1txD.js

js midnight-link.base44.app collected 2026-10-03 05:33:30 UTC 6,203 bytes, 1 lines download raw bytes

1import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{P as t,_ as n,h as r,j as i,n as a}from"./axiosClient-DnVO32-R.js";import{i as o}from"./runtime-QtgwY_nV.js";import{r as s}from"./domainValidation-FMKryCR2.js";import{b as c,g as l,n as u}from"./backend-CC2lXJt_.js";import{_ as d,b as f}from"./vendor-react-Ccu8BlQU.js";import{i as p,o as m}from"./i18n-pkgydE_c.js";import{T as h}from"./errorReporting-C8KVtz7O.js";import{g,u as _,y as v}from"./mixpanelUtils-CtEUaRBr.js";import{n as y}from"./base-DLGBKAFy.js";import{t as b}from"./AuthAPI-C4-6oDY6.js";import{r as x}from"./useDesignSystem-CehPfIkU.js";import{r as S}from"./logoutReturnPath-HjtsxsFd.js";var C=e(f()),w=`sso_workspace_challenge_pending`,T=6e5;function E(e,t){try{sessionStorage.setItem(w,JSON.stringify({workspaceId:e,workspaceName:t,startedAt:Date.now()}))}catch{}}function D(){try{let e=sessionStorage.getItem(w);if(!e)return null;let t=JSON.parse(e);return t?.workspaceId?Date.now()-(t.startedAt??0)>T?(sessionStorage.removeItem(w),null):t:null}catch{return null}}function O(){try{sessionStorage.removeItem(w)}catch{}}function k(){let e=D();if(e)try{sessionStorage.removeItem(w)}catch{}return e}var A=new class extends y{getBaseURL(){return`/auth`}prepareChallenge(e){return this.axios.post(`/sso-challenge/prepare`,{workspace_id:e})}passwordChallenge(e,t){return this.axios.post(`/workspace-challenge`,{workspace_id:e,password:t})}},j=(e,t)=>{let n=encodeURIComponent(t),r=e.indexOf(`#`),i=(r===-1?e:e.slice(0,r)).replace(/(\/workspace\/)[^/?#]+/,`$1${n}`),a=i.indexOf(`?`),o=a===-1?i:i.slice(0,a),s=(a===-1?``:i.slice(a+1)).split(`&`).filter(e=>e&&!/^active_workspace=/.test(e));return s.push(`active_workspace=${n}`),`${o}?${s.join(`&`)}`},M=({workspaceId:e,fromUrl:t,email:n})=>{let r=new URLSearchParams({from_url:j(t,e)}),i=n?.trim();i&&r.set(`login_hint`,i);let a=new URLSearchParams(window.location.search),o=a.get(`mcp_oauth_context`);o&&r.set(`mcp_oauth_context`,o);let s=a.get(`ref`);return s&&r.set(`ref`,s),`${u()}/workspaces/${e}/auth/sso/login?${r.toString()}`},N=`oauth_pending_prompt`,P=2e3,F=3e5;function I(e){if(!e)return`/`;if(e.length<=P)return e;try{let t=new URL(e,window.location.origin),n=t.searchParams.get(`prompt`);if(n){let r={prompt:n,timestamp:Date.now()};return sessionStorage.setItem(N,JSON.stringify(r)),t.searchParams.delete(`prompt`),e.startsWith(`http://`)||e.startsWith(`https://`)?t.href:t.pathname+t.search+t.hash}}catch{}return e}function L(){try{let e=sessionStorage.getItem(N);if(sessionStorage.removeItem(N),!e)return null;let t=JSON.parse(e);if(t.prompt&&t.timestamp&&Date.now()-t.timestamp<F)return t.prompt}catch{}return null}function R(){try{let e=sessionStorage.getItem(N);if(!e)return!1;let t=JSON.parse(e);return!!(t.prompt&&t.timestamp&&Date.now()-t.timestamp<F)}catch{return!1}}var z=(e,t)=>`${e}${e.includes(`?`)?`&`:`?`}continuation=${encodeURIComponent(t)}`,B=0;function V(){B++}async function H({workspaceId:e,workspaceName:t,userEmail:n}){let r=++B,i=I(s(window.location.href,`/`));try{let{continuation:a}=await A.prepareChallenge(e);return r===B?(E(e,t??``),window.location.href=z(M({workspaceId:e,fromUrl:i,email:n??void 0}),a),`redirected`):`superseded`}catch{return r===B?(O(),`failed`):`superseded`}}var U=null;function W(){!c(window.location.host)&&!o()||(U=t.ensureSessionReady().then(()=>{let e=i(!1);return e?(p(`Authorization`,`Bearer ${e}`),b.getCurrentUser()):null}),U.catch(()=>{}))}function G(){let e=U;return U=null,e}var K=()=>{try{v(`logged_in`,`true`)}catch{}},q=()=>{try{g(`logged_in`)}catch{}};function J(e){let t=e.split(`:`,1)[0].toLowerCase(),n=l();return!!(t===new URL(`https://app.base44.com`).hostname||n&&t===n)}function Y(e){let t=`${e.pathname}${e.search}${e.hash}`;return`/auth/oidc/login?return_to=${encodeURIComponent(t)}`}function X(e){return J(e)?`/api/auth/oidc/logout`:null}var Z=d(),Q=(0,C.createContext)(),$=e=>e.response?.status===401,ee=({children:e})=>{let[o,s]=(0,C.useState)(null),[c,l]=(0,C.useState)(!1),[u,d]=(0,C.useState)(!0),f=()=>{q(),localStorage.removeItem(`token`),localStorage.removeItem(`base44_access_token`),localStorage.removeItem(`home_draft_prompt`),localStorage.removeItem(`home_draft_connectors`),localStorage.removeItem(`home_draft_pinned_url`),localStorage.removeItem(`home_draft_pinned_mode`),localStorage.removeItem(`activeWorkspaceId`),m(`Authorization`),r(),V(),O(),_(null),s(null),l(!1),d(!1)},g=e=>{_(e?.feature_flag_variants,e?.analytics_arms),s(e)};(0,C.useEffect)(()=>{n(()=>o?.email??null)},[o?.email]),(0,C.useEffect)(()=>{x(h(o?.email))},[o?.email]),(0,C.useEffect)(()=>{let e=!1,n=()=>{};return t.ensureSessionReady().then(()=>
1{if(e)return;let r=i(!0);r?(localStorage.setItem(`token`,r),p(`Authorization`,`Bearer ${r}`),w()):d(!1);let a=t.getPrincipalId(),o=()=>{if(t.getPrincipalId()!==a){m(`Authorization`),m(`SSO_AUTHORIZATION`),window.location.reload();return}let e=i(!1);e?p(`Authorization`,`Bearer ${e}`):m(`Authorization`)},s=e=>{e.storageArea===localStorage&&(e.key===null||e.key===`token`||e.key===`base44_access_token`)&&o()},c=t.addListener(e=>{e===`token_changed`&&(a===`anon`&&(a=t.getPrincipalId()),o())});window.addEventListener(`storage`,s),window.addEventListener(`focus`,o),n=()=>{c(),window.removeEventListener(`storage`,s),window.removeEventListener(`focus`,o)}}),a(e=>{$(e)&&f()}),()=>{e=!0,n()}},[]);let v=e=>{s(t=>({...t,...e}))},y=async(e=!0)=>{let t=e?X(window.location.host):null,{href:n,pathname:r,search:i,hash:a}=window.location;if(f(),t){S(r+i+a),window.location.href=t;return}let o=b.logout().catch(()=>{});e&&await o,e&&(window.location.href=`/login?from_url=`+encodeURIComponent(n))},w=async()=>{try{d(!0);let e=G(),t=(e?await e:null)??await b.getCurrentUser();return g(t),l(!0),d(!1),K(),t}catch(e){d(!1);let t=e.response?.status;(t===401||t===403)&&f()}},T=(0,C.useCallback)(async({fresh:e=!1}={})=>{let t=await b.getCurrentUser({fresh:e});t&&(g(t),l(!0),d(!1))},[]);return(0,Z.jsx)(Q.Provider,{value:{user:o,isAuthenticated:c,logout:y,isLoadingAuth:u,updateUser:v,reloadUser:T},children:e})},te=()=>(0,C.useContext)(Q);export{D as _,W as a,z as c,I as d,j as f,k as g,O as h,J as i,R as l,A as m,te as n,H as o,M as p,Y as r,V as s,ee as t,L as u,E as v};

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.