1import{c as E,r as D,j as Q}from"./__vite-browser-external-CPRS3umU.js";import{n as R,o as T,u as M,i as U,a as $,b as W,cT as X,m as j,L as V,l as n,p as s,cU as b,cV as G,b4 as y,cW as Y,q as d,cX as B}from"./main-DVHLog1p.js";import{d as z,e as J,f as Z,h as ee,s as w}from"./oauth-store-CCPT9F5s.js";import{g as te}from"./device-id-provider-DVvE4Qxz.js";try{let e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="c0249d60-1918-4312-8e6f-bf82a4d24680",e._sentryDebugIdIdentifier="sentry-dbid-c0249d60-1918-4312-8e6f-bf82a4d24680")}catch{}const re=async e=>await T("/auth/mfa/check",e),ie=()=>{const e=E.c(1);let t;return e[0]===Symbol.for("react.memo_cache_sentinel")?(t={mutationFn:ne},e[0]=t):t=e[0],R(t)};async function ne(e){const t=await re(e);if(!t)throw new Error("No response received from MFA check");return t}async function se(e){return T("/auth/consumer/check-linking-status",e)}const ae=()=>{const e=E.c(1);let t;return e[0]===Symbol.for("react.memo_cache_sentinel")?(t={mutationFn:oe},e[0]=t):t=e[0],R(t)};async function oe(e){const t=await se(e);if(!t)throw new Error("Failed to get consumer linking status");return t}async function ce(e){return T("/auth/check-linking-status",e)}function ue(){const e=E.c(1);let t;return e[0]===Symbol.for("react.memo_cache_sentinel")?(t={mutationFn:le},e[0]=t):t=e[0],R(t)}async function le(e){const t=await ce(e);if(!t)throw new Error("Failed to get linking status");return t}const de={consumer:s.consumer.auth.loginPhone.getHref(),professional:s.auth.login.getHref(),enterprise:s.enterprise.login.getHref()},fe={consumer:s.client.index.getHref(),professional:s.business.getHref(),enterprise:s.enterprise.dashboard.getHref()},he=15e3;function ge(){return new Promise(e=>{let t;const g=B.listen("auth",({payload:f})=>{f.event==="signInWithRedirect"&&(t&&clearTimeout(t),g(),e({success:!0})),f.event==="signInWithRedirect_failure"&&(t&&clearTimeout(t),g(),e({success:!1,error:f.data}))});t=setTimeout(()=>{g(),e({success:!1,error:new Error("OAuth Hub event timed out")})},he)})}const Ae=()=>{const e=M(),[t]=U(),g=t.get("redirectTo"),{toast:f}=$(),{mutateAsync:q}=ue(),{mutateAsync:L}=ae(),{mutateAsync:H}=ie(),v=W({preventNavigate:!0}),P=X(),c=j();return D.useEffect(()=>{const u=async(a,o)=>{try{await v.mutateAsync()}catch(r){n.error("Failed to sign out:",r)}e(de[a]),o&&f({variant:"destructive",title:o.title,description:o.description})},m=async(a,o,r)=>{await c.invalidateQueries({queryKey:d.auth._def}),e(r||fe[a]),o&&f({variant:"default",title:o.title,description:o.description})},F=async()=>{await c.invalidateQueries({queryKey:d.auth.linkedIdentityProviders.queryKey}),await c.invalidateQueries({queryKey:d.auth.consumerIdentityProviders.queryKey}),await c.invalidateQueries({queryKey:d.auth.onboardingStatus.queryKey}),await c.invalidateQueries({queryKey:d.users.me.queryKey}),await c.invalidateQueries({queryKey:d.consumers.me.queryKey})};(async()=>{var _,O,C,I;const{provider:a,redirectPath:o,accountType:r}=z(),N=J();Z(),ee();const p=o;if(!a||!r){n.error("No provider or account type found: Signing out and redirecting to home page");try{await v.mutateAsync()}catch(h){n.error("Failed to sign out:",h)}e(s.root.getHref());return}try{const h=await ge();if(!h.success){n.error("OAuth Hub event failed or timed out:",h.error),await u(r,{title:"Login failed",description:"Social login timed out. Please try again."});return}const S=await b({forceRefresh:!0}),x=G(),K=(_=S.tokens)==null?void 0:_.idToken,l=((O=S.tokens)==null?void 0:O.accessToken)||N;if(!K&&!l&&!x){n.error("Failed to fetch tokens from Amplify: No idToken or accessToken"),await u(r,{title:"Login failed",description:"No social login available. Please sign in with email and password."});return}let i=null;if(r==="consumer"?(i=await L({provider:a,oauthAccessToken:(l==null?void 0:l.toString())||""}),i.tokenRefreshRequired===!0&&await b({forceRefresh:!0})):i=await q({provider:a,oauthAccessToken:(l==null?void 0:l.toString())||""}),(i==null?void 0:i.wasLinked)===!0){if(i!=null&&i.tokenRefreshRequired)try{await b({forceRefresh:!0}),await F()}catch{}if(p){await m(r,{title:"Account linked",description:`Your ${a} account was linked successfully. Please sign in again to continue.`},p);return}if(r!=="consumer"){await m(r,{title:"Account Linked",description:`Your ${a} account was linked successfully. Please sign in again to continue.`});return}}if(r==="consumer"){if(i.userExists===!0){n.error("User exists: Showing error and redirecting to login page"),w(y.PROFESSIONAL_EXISTS
1),await u(r);return}if(i.consumerExists===!1){const k=(I=(C=S.tokens)==null?void 0:C.idToken)==null?void 0:I.payload.email;if(!k||typeof k!="string"){n.error("Failed to create consumer record: Email not found in idToken payload"),w(y.INVALID_RESPONSE),await u(r);return}try{await Y({firstName:"",lastName:"",primaryEmail:k,refreshToken:""})}catch(A){if(n.error("Failed to create consumer record:",A),A instanceof Error&&A.message.includes("This account is already registered as a contractor.")){w(y.PROFESSIONAL_EXISTS),await u(r);return}throw A}}await m(r,void 0,p);return}else if(r==="professional"||r==="enterprise"){if(i.consumerExists===!0){n.error("Consumer exists: Showing error and redirecting to login page"),w(y.CONSUMER_EXISTS),await u(r);return}if(i.userExists===!1){await P.mutateAsync(),await c.invalidateQueries({queryKey:d.auth._def}),e(r==="professional"?s.auth.onboarding.getHref(g||""):s.enterprise.onboarding.getHref());return}else{if(await m(r,void 0,p),(await H({deviceId:te()})).mfaRequired===!0){e(s.auth.oauthMfaVerify.getHref(),{state:{accountType:r}});return}await m(r);return}}throw new Error("Something went wrong. Please try again.")}catch(h){n.error("OAuth callback error:",h),w(y.EMAIL_AND_PASSWORD_REQUIRED),await u(r)}})()},[]),Q.jsx(V,{style:"fullscreen"})};export{Ae as default}; 2//# sourceMappingURL=oauth-callback-BX3RkYu9.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.