PageSourceSearch

https://kindredly.ai/js/AuthProviderLoginBHfUwDVh.js

js kindredly.ai collected 2026-09-24 14:30:25 UTC 13,433 bytes, 1 lines download raw bytes

1import{m as R}from"./main.mixin7s_FZSSe.js";import{N as C,_ as U}from"./chunkReloadRecoveryC4XyrbqR.js";import{s as $}from"./gmailIntegrationrZpKOK1n.js";import{c as T,r as _,g as x}from"./authCallbackIssuerDvaIHHxy.js";import{D as I,t as p}from"./providerAuthFlowDKxKqfUO.js";import{d as H,a4 as k,b as d,o as g,j as v,w as B,x as f,B as b,C as y}from"./vue-runtimeBcw72k-n.js";import"./refresh.storeCFjy7nst.js";import"./OperationQueueDV3oPNrt.js";import"./item-name.utilsCH3lkmjj.js";import"./dexie2jmnBxhj.js";import"./item.typesx7Q7rrX9.js";import"./content.typesCQ2lHcy0.js";import"./constantsDsHwd9pV.js";import"./extraction.pure.utilsDQPW8yIh.js";import"./url.utilsCetgXmY_.js";import"./file_utilsBz4gEirg.js";import"./agentParentalGrantCz4Xs1Ac.js";import"./common.storeB-dDF-ne.js";import"./adminsite.storeDQcNSYX0.js";import"./modal.mixinDnpIrxXn.js";import"./browserTabsDwRj8B1n.js";import"./scopedSettingsB4ZfLk-4.js";import"./subscription.storeD0D3zB45.js";import"./bootstrap-vue-nextD6HU9H8G.js";import"./cjs-helpersC4iS2aBk.js";function m(e){return e?{serverBaseURLOverride:e}:{}}const F=H({name:"AuthProviderLogin",mixins:[R],data(){return{authSuccess:null,errorMessage:null,loading:!1,sourceId:null,loginType:null,authType:null,sessionToken:null,failToken:null,rawState:null,callbackServerHostname:null,callbackServerBaseURL:null,timeleft:3}},mounted(){},computed:{},methods:{getRedirectServerHostname(e){return x(e||this.config.serverHostname,this.config.publicServerHostname)||this.config.serverHostname},appendParams(e,t){if(t){if(t instanceof URLSearchParams){for(const[s,a]of t.entries())e.has(s)||e.set(s,a);return}for(const[s,a]of Object.entries(t))a==null||e.has(s)||e.set(s,String(a))}},extractHashQueryParams(e){if(!e)return new URLSearchParams;const t=e.startsWith("#")?e.substring(1):e,s=t.indexOf("?");return s<0?new URLSearchParams(t):new URLSearchParams(t.substring(s+1))},getOauthCallbackParams(){var a,o;const e=typeof((a=this.$route)==null?void 0:a.hash)=="string"?this.$route.hash:"",t=typeof window<"u"&&window.location.hash||"",s=new URLSearchParams;return this.appendParams(s,(o=this.$route)==null?void 0:o.query),this.appendParams(s,this.extractHashQueryParams(e)),this.appendParams(s,this.extractHashQueryParams(t)),s},getRawState(){return this.getOauthCallbackParams().get("state")||new URLSearchParams(window.location.search.substring(1)).get("state")||this.$route.query.state||null},parseProviderState(e){if(!e)return{sessionToken:null,failToken:null,sourceId:null,authType:null,loginType:null};if(e.startsWith("gmail:"))return{sessionToken:e,failToken:null,sourceId:null,authType:null,loginType:null};if(!e.includes("="))return{sessionToken:e,failToken:null,sourceId:null,authType:null,loginType:null};const t=e.split(",").reduce((s,a)=>{const[o,...c]=a.split("=");return!o||c.length===0||(s[decodeURIComponent(o)]=decodeURIComponent(c.join("="))),s},{});return{sessionToken:t.session||null,failToken:t.failToken||null,sourceId:t.sourceId||null,authType:t.authType||null,loginType:t.loginType||null,serverBaseURL:t.serverBaseURL||null,serverHostname:t.serverHostname||null}},getRegisterCallbackParams(){const e=new URLSearchParams(window.location.search.substring(1)),t=this.getOauthCallbackParams();for(const[s,a]of t.entries())e.has(s)||e.set(s,a);return!e.has("loginType")&&this.loginType&&e.set("loginType",this.loginType),this.sourceId&&!e.has("sourceId")&&e.set("sourceId",this.sourceId),e},buildRegisterTarget(){const e=this.getRegisterCallbackParams().toString();return`${this.appPrefix}#/register${e?`?${e}`:""}`},buildTokenLoginTarget(e,t){const s=new URLSearchParams;return s.set("token",t),this.sessionToken&&s.set("session",this.sessionToken),this.failToken&&s.set("failToken",this.failToken),this.sourceId&&s.set("sourceId",this.sourceId),e.serverBaseURL&&s.set("serverBaseURL",e.serverBaseURL),e.serverHostname&&s.set("serverHostname",e.serverHostname),`${this.appPrefix}#/auth/tokenLoginRequest?${s.toString()}`},async preflightRegisterCallback(e){var a;const t=["app","extension"].includes(this.sourceId||"")?{target:null,authSuccess:!0}:{target:this.buildRegisterTarget(),authSuccess:!1};if(e.loginType!=="google"||!this.sessionToken)return t;const s=await this.typedSendReq("/auth/providerLogin/verify",{sessionToken:this.sessionToken,accessToken:e.providerAuthValue,loginType:e.loginType,state:this.rawState},m(e.serverContext.serverBaseURL));return s!=null&&s.success&&((a=s==null?void 0:s.result)!=null&&a.token)?this.sourceId==="extension"?t:{target:this.buildTokenLoginTarget(e.serverContext,s.result.token),authSuccess:!1}:t},handoffToRegister(e){window.location.replace(e||this.buildRegisterTarget())},getSafeRedirectTarget(){const e=this.$route.query.target;return e&&e.startsWith("/")&&!e.startsWith("//")?e:this.isNativeClient?"/":this.appPrefix}
1,getTerminalFailureStatus(e){return e==="access_denied"?"cancelled":"failed"},async getAuthCallbackServerContext(){const e=this.parseProviderState(this.rawState),t=await _({sourceId:this.sourceId,sessionToken:this.sessionToken,failToken:this.failToken,stateServerBaseURL:e.serverBaseURL,stateServerHostname:e.serverHostname,queryServerBaseURL:this.$route.query.serverBaseURL,queryServerHostname:this.$route.query.serverHostname});return this.callbackServerHostname=t.serverHostname,this.callbackServerBaseURL=t.serverBaseURL,t},async reportProviderFailure(e,t){if(!(!this.sessionToken||this.sessionToken.startsWith("gmail:")))try{if(!this.failToken)return;await this.typedSendReq("/auth/providerLogin/fail",{sessionToken:this.sessionToken,failToken:this.failToken,status:e,message:t},m(this.callbackServerBaseURL))}catch(s){console.warn("Failed to persist provider auth failure state",s)}finally{await T(this.sessionToken)}},async performTokenLogin(e){try{const t=await this.typedSendReq("/auth/tokenLogin",{token:e.authToken},m(e.serverBaseURLOverride));if(!(t!=null&&t.success)){const s=(t==null?void 0:t.message)||"Authentication failed. Please try again.";return await this.reportProviderFailure("failed",s),{success:!1,message:s}}return await T(this.sessionToken),{success:!0}}catch(t){const s=t instanceof Error?t.message:"Authentication failed. Please try again.";return await this.reportProviderFailure("failed",s),{success:!1,message:s}}},async completeProviderCallback(e){var s,a,o,c;const t={value:"verifying-provider-callback"};try{const r=await this.typedSendReq("/auth/providerLogin/verify",{sessionToken:this.sessionToken,accessToken:e.providerAuthValue,loginType:e.loginType,state:this.rawState},m(e.serverBaseURLOverride));if(!(r!=null&&r.success)){const i=p(t,{type:"VERIFY_FAILED",message:r==null?void 0:r.message}),u="message"in i?i.message:"Authentication failed. Please try again.";return await this.reportProviderFailure("failed",u),{success:!1,message:u}}if((s=r==null?void 0:r.result)!=null&&s.existingAccount){const i=p(t,{type:"VERIFY_EXISTING_ACCOUNT",message:(a=r==null?void 0:r.result)==null?void 0:a.message}),u="message"in i?i.message:"Authentication failed. Please try again.";return await this.reportProviderFailure("failed",u),{success:!1,message:u}}const l=(o=r==null?void 0:r.result)==null?void 0:o.token;if(!l){const i=p(t,{type:"VERIFY_MISSING_TOKEN",message:(c=r==null?void 0:r.result)==null?void 0:c.message}),u="message"in i?i.message:"Authentication failed. Please try again.";return await this.reportProviderFailure("failed",u),{success:!1,message:u}}return this.sourceId==="extension"?(await T(this.sessionToken),{success:!0}):await this.performTokenLogin({authToken:l,serverBaseURLOverride:e.serverBaseURLOverride})}catch(r){const l=p(t,{type:"VERIFY_FAILED",message:r instanceof Error?r.message:void 0}),i="message"in l?l.message:"Authentication failed. Please try again.";return await this.reportProviderFailure("failed",i),{success:!1,message:i}}},async closeAfterDelay(e){await this.countDown(e),this.closeWindow()},async countDown(e){for(this.timeleft=e;this.timeleft>0;)this.timeleft-=1,await new Promise(t=>setTimeout(t,1e3))},async closeExternalSigninSurfaceIfNeeded(){if(!(this.sourceId!=="app"||!this.isNativeClient))try{await C.sendAppRequest({action:"CLOSE_SIGNIN_WINDOW"})}catch(e){console.warn("Unable to close external sign-in surface after provider login callback",e)}},getProviderAuthValue(e,t,s){return s==="apple"?e.get("code")||this.$route.query.code||null:t.get("access_token")||t.get("accessToken")||e.get("access_token")||e.get("accessToken")||this.$route.query.access_token||this.$route.query.accessToken||null},async providerLogin(){this.loading=!0;try{const e=await this.getAuthCallbackServerContext(),t=this.getOauthCallbackParams(),s=new URLSearchParams(window.location.search.substring(1)),a=this.loginType||"google",o=this.getProviderAuthValue(s,t,a),c=t.get("error")||s.get("error")||this.$route.query.error||null;if(c){this.errorMessage=c.replaceAll("_"," "),this.authSuccess=!1,await this.reportProviderFailure(this.getTerminalFailureStatus(c),this.errorMessage),await this.closeAfterDelay(2);return}let r=this.sessionToken;if(typeof r=="string"&&r.startsWith("gmail:")){const i=s.get("code")||this.$route.query.code;if(!i){this.errorMessage="Missing OAuth code",this.authSuccess=!1,await this.closeAfterDelay(2);return}const u=this.sourceId==="app"?"/auth/providerLogin/app":"/auth/providerLogin/extension",w=this.getRedirectServerHostname(e.serverHostname),L=`${w}${u}`,n=await this.typedSendReq("/user/integrations/gmail/oauth/exchangeCode",{code:i,redirectUri:L},m(e.serverBaseURL));if(!(n!=null&&n.success)){this.errorMessage=(n==null?void 0:n.message)||"Gmail connection failed",this.authSuccess=!1,await this.closeAfterDelay(2);return}const h=(n==null?void 0:n.result)||(n==null?void 0:n.results)||{},S=String((h==null?void 0:h.accessToken)||"").trim(),P=Math.max(0,Math.round(Number((h==null?void 0:h.expiresInSec)||0))),A=String((h==null?void 0:h.scope)||"").trim()||void 0;if(S&&P&&await $({accessToken:S,scope:A,obtainedAtMs:Date.now(),expiresAtMs:Date.now()+P*1e3}),this.authSuccess=!0,this.loading=!1,await this.countDown(2),this.sourceId==="extension"||window.opener){try{window.close()}catch{}return}window.location.href=`${w}/#/settings/email`;return}if(this.authType==="register"){if(!o||!r){this.errorMessage=I,this.authSuccess=!1,await this.closeAfterDelay(2);return}const i=await this.preflightRegisterCallback({providerAuthValue:o,loginType:a,serverContext:e});if(this.loading=!1,i.target){this.handoffToRegister(i.target);return}this.authSuccess=i.authSuccess,await this.closeAfterDelay(2);return}if(!o||!r){this.errorMessage=I,this.authSuccess=!1,await this.closeAfterDelay(2);return}const l=await this.completeProviderCallback({providerAuthValue:o,loginType:a,serverBaseURLOverride:e.serverBaseURL});if(l.success&&(this.authSuccess=!0,this.loading=!1,["extension","app"].includes(this.sourceId||"")?await this.closeAfterDelay(2):window.location.href=`${this.getRedirectServerHostname(e.serverHostname)}
1${this.getSafeRedirectTarget()}`),!l.success){const i=l.message;console.error("Error:",i),this.errorMessage=i,this.authSuccess=!1,await this.closeAfterDelay(2)}}catch(e){const t=e instanceof Error?e.message:"Authentication failed. Please try again.";this.errorMessage=t,this.authSuccess=!1,await this.reportProviderFailure("failed",t),await this.closeAfterDelay(2)}finally{this.loading=!1}},closeWindow(){const e=this.getRedirectServerHostname(this.callbackServerHostname);this.isNativeClient&&!window.opener?(this.closeExternalSigninSurfaceIfNeeded(),this.$router.push(this.getSafeRedirectTarget())):this.sourceId=="extension"?window.close():this.sourceId=="app"?this.isNativeClient?(this.closeExternalSigninSurfaceIfNeeded(),this.$router.push(this.getSafeRedirectTarget())):window.location.href=`${e}${this.getSafeRedirectTarget()}`:window.location.href=`${e}${this.getSafeRedirectTarget()}`}},created(){this.rawState=this.getRawState();const e=this.parseProviderState(this.rawState);this.sessionToken=e.sessionToken,this.failToken=e.failToken,this.sourceId=this.$route.params.sourceId||e.sourceId,this.authType=e.authType,this.loginType=this.$route.query.loginType||this.$route.params.loginType||e.loginType,!this.loginType||["google","apple"].includes(this.loginType)?this.providerLogin():this.showToast("Invalid provider",{variant:"danger"})}}),D={class:"text-center"},E={key:0},q={key:0,class:"mt-2 text-muted"},N={key:1},M={key:2},O={key:0,class:"mt-2"},V={key:1,class:"mt-3"};function W(e,t,s,a,o,c){const r=k("b-spinner"),l=k("b-icon"),i=k("b-container");return g(),d("div",D,[v(i,{class:"mt-5 justify-content-center"},{default:B(()=>[!e.loading&&e.authSuccess===!1?(g(),d("div",E,[t[0]||(t[0]=b(" Authentication failed. ",-1)),e.errorMessage?(g(),d("div",q,y(e.errorMessage),1)):f("",!0)])):f("",!0),e.loading?(g(),d("div",N,[v(r,{style:{width:"3rem",height:"3rem"},label:"Loading current status...",variant:"primary"})])):f("",!0),!e.loading&&e.authSuccess===!0?(g(),d("div",M,[v(l,{icon:"check-circle-fill",class:"success-color"}),t[1]||(t[1]=b(" Authentication successful! ",-1)),e.isExtension&&e.timeleft<0?(g(),d("div",O," Please close this window and return to the Kindredly "+y(e.isNativeClient?"App":"extension tab")+". ",1)):f("",!0),["extension","app"].includes(e.sourceId)&&e.timeleft<2?(g(),d("div",V," You close this window and return to Kindredly "+y(e.isNativeClient?"App":"extension tab")+". ",1)):f("",!0)])):f("",!0)]),_:1})])}const pe=U(F,[["render",W]]);export{pe 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.