1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[357],{357:(e,t,n)=>{n.r(t),n.d(t,{StagingDomainAuthFix:()=>r});var a=n(12212),i=n(98614),o=n(44335);function r(){let{fetchProfile:e}=function(){let{user:e,session:t,refreshProfile:n}=(0,i.W)(),[o,r]=(0,a.useState)(null),s=(0,a.useCallback)(()=>(null==t?void 0:t.access_token)?t.access_token:null,[t]);return(0,a.useEffect)(()=>{if(!window.location.hostname.includes("staging.apprendo.co"))return;if((()=>{if(window.location.hash&&(window.location.hash.includes("access_token=")||window.location.hash.includes("id_token="))){let e=new URLSearchParams(window.location.hash.substring(1)),t=e.get("access_token");if(t&&t.startsWith("eyJ")&&3===t.split(".").length){let n={access_token:t,refresh_token:e.get("refresh_token")||"",expires_in:parseInt(e.get("expires_in")||"3600",10),token_type:e.get("token_type")||"bearer",user:{id:"pending"}};return localStorage.setItem("sb-lpjvndsvkvqgkdkvacnn-auth-token",JSON.stringify(n)),window.history.replaceState&&window.history.replaceState(null,"",window.location.pathname+window.location.search)}console.warn("[useProfileFetch] Invalid access token format in URL hash")}})(),null==e?void 0:e.id)localStorage.setItem("staging_auth_user_id",e.id),r(e.id);else{let e=localStorage.getItem("staging_auth_user_id");e&&r(e)}let t=e=>{if("sb-lpjvndsvkvqgkdkvacnn-auth-token"===e.key)try{if(e.newValue){var t;let n=JSON.parse(e.newValue);(null==n||null==(t=n.user)?void 0:t.id)&&"pending"!==n.user.id&&(localStorage.setItem("staging_auth_user_id",n.user.id),r(n.user.id))}}catch(e){console.error("[useProfileFetch] Error handling storage event:",e)}};window.addEventListener("storage",t);let n=window.fetch;return window.fetch=async function(t,a){let i="string"==typeof t?t:t instanceof URL?t.href:t.url,r=o||(null==e?void 0:e.id)||localStorage.getItem("staging_auth_user_id");if(i.includes("/api/")){let e={...a,headers:{...(null==a?void 0:a.headers)||{}}};r&&(e.headers={...e.headers,"x-user-id":r});let o=s();return o&&(e.headers={...e.headers,Authorization:"Bearer ".concat(o)}),e.headers={...e.headers,"x-staging-fallback":"true"},i.includes("/api/auth/profile"),n(t,e)}return n(t,a)},()=>{window.removeEventListener("storage",t),window.fetch=n}},[e,t,o,s]),{fetchProfile:(0,a.useCallback)(async()=>{try{var t,n;let a=o||(null==e?void 0:e.id)||localStorage.getItem("staging_auth_user_id"),i=s(),l={"x-staging-fallback":"true"};a&&(l["x-user-id"]=a),i&&(l.Authorization="Bearer ".concat(i));let c=await fetch("/api/auth/profile",{headers:l,credentials:"include"});if(!c.ok)return console.error("[useProfileFetch] Profile fetch failed:",c.status),null;let d=await c.json();if(null==d||null==(t=d.authUser)?void 0:t.id){localStorage.setItem("staging_auth_user_id",d.authUser.id),r(d.authUser.id);try{let e="sb-lpjvndsvkvqgkdkvacnn-auth-token",t=localStorage.getItem(e);if(t)try{let a=JSON.parse(t);(null==(n=a.user)?void 0:n.id)!=="pending"&&a.user||(a.user=d.authUser,localStorage.setItem(e,JSON.stringify(a)))}catch(e){console.error("[useProfileFetch] Error updating session in localStorage:",e)}}catch(e){console.error("[useProfileFetch] Error handling session update:",e)}}return d}catch(e){return console.error("[useProfileFetch] Error fetching profile:",e),null}},[e,o,s]),activeUserId:o,hasLocalStorageSession:!!localStorage.getItem("sb-lpjvndsvkvqgkdkvacnn-auth-token")}}(),t=(0,i.W)();return(0,a.useEffect)(()=>{if(!window.location.hostname.includes("staging.apprendo.co"))return;let t=(0,o.createBrowserClient)();(async()=>{if(window.location.hash&&window.location.hash.includes("access_token="))try{let{data:e,error:n}=await t.auth.getSession();if(n)return console.error("[StagingDomainAuthFix] Error getting session:",n.message),!1;if(e.session){let t=e.session.user.id;if(localStorage.setItem("staging_auth_user_id",t),window.history.replaceState&&window.history.replaceState(null,"",window.location.pathname+window.location.search),window.location.pathname.includes("/login"))return window.location.href="/dashboard",!0}}catch(e){console.error("[StagingDomainAuthFix] Error handling URL hash:",e)}return!1})().then(n=>
1{n||t.auth.getSession().then(t=>{let{data:n,error:a}=t;if(a)return void console.error("[StagingDomainAuthFix] Error getting session:",a.message);n.session?(localStorage.setItem("staging_auth_user_id",n.session.user.id),window.location.pathname.includes("/login")&&(window.location.href="/dashboard"),e().then(e=>{})):window.location.pathname.includes("/dashboard")&&(window.location.href="/login")})});let{data:{subscription:n}}=t.auth.onAuthStateChange((e,t)=>{"TOKEN_REFRESHED"!==e&&("SIGNED_IN"===e&&t?(localStorage.setItem("staging_auth_user_id",t.user.id),window.location.pathname.includes("/login")&&(window.location.href="/dashboard")):"SIGNED_OUT"===e&&(localStorage.removeItem("staging_auth_user_id"),window.location.pathname.includes("/dashboard")&&(window.location.href="/login")))}),a=window.fetch;return window.fetch=async function(e,n){let i="string"==typeof e?e:e instanceof URL?e.href:e.url;if(i.includes("_rsc=")&&i.includes("/dashboard/")&&(i.includes("/chat")||i.includes("/stats")||i.includes("/podcast")||i.includes("/recommendations")||i.includes("/subscribers")||i.includes("/settings")))return a(e,n);if(i.includes("/api/"))try{let{data:{user:i},error:o}=await t.auth.getUser(),{data:{session:r}}=await t.auth.getSession();if(i&&(null==r?void 0:r.access_token)){let t={...n,headers:{...(null==n?void 0:n.headers)||{}}};return t.headers={...t.headers,"x-user-id":i.id,Authorization:"Bearer ".concat(r.access_token),"x-staging-fix":"true"},a(e,t)}}catch(e){console.error("[StagingDomainAuthFix] Error intercepting fetch:",e)}return a(e,n)},()=>{n.unsubscribe(),window.fetch=a}},[e,t]),null}}}]); 2//# sourceMappingURL=357.bc6dd63750a13480.js.map
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.