"use strict";(globalThis["webpackChunksynclounge"]=globalThis["webpackChunksynclounge"]||[]).push([[9897],{6186:(t,e,i)=>{i.r(e),i.d(e,{default:()=>C});var s=i(2202),n=i(7179),a=i(3058),l=i(5223),h=i(4437),_=i(6035),c=i(2469),o=i(5294),r=function(){var t=this,e=t._self._c;return e(_.Z,{staticClass:"fill-height"},[e(o.Z,{attrs:{align:"center",justify:"center"}},[e(h.Z,[e(a.Z,{staticClass:"mx-auto",attrs:{"max-width":"550",loading:t.loading}},[t.GET_PLEX_AUTH_TOKEN&&!1===t.IS_USER_AUTHORIZED?e(s.Z,{attrs:{type:"error"}},[t._v(" You are not authorized to access this server ")]):t._e(),e(l.EB,[e(c.Z,{attrs:{contain:"",src:i(5970)}})],1),e(l.h7,[e(n.Z,{staticClass:"primary",attrs:{target:"_blank","x-large":"",text:"",disabled:t.allowSignIn,href:t.plexAuthUrl},on:{click:t.authenticate}},[t._v(" Sign in ")])],1)],1)],1)],1)],1)},E=[],u=(i(7658),i(629)),T=i(7501);const A=t=>{const e=`; ${document.cookie}`,i=e.split(`; ${t}=`);return 2===i.length?i.pop().split(";").shift():null},p=A,d={name:"SignIn",data:()=>({loading:!1,plexAuthResponse:null,cancelToken:null}),computed:{...(0,u.Se)(["GET_CONFIG"]),...(0,u.Se)("plex",["GET_PLEX_AUTH_URL","IS_USER_AUTHORIZED","GET_PLEX_AUTH_TOKEN"]),plexAuthUrl(){return this.plexAuthResponse?this.GET_PLEX_AUTH_URL(this.plexAuthResponse.code):""},allowSignIn(){return this.loading||!this.plexAuthResponse||!this.IS_USER_AUTHORIZED&&!!this.GET_PLEX_AUTH_TOKEN}},async created(){if(this.IS_USER_AUTHORIZED&&this.GET_PLEX_AUTH_TOKEN)return void this.redirect();const t=p("mpt");t?await this.cookieAuth(t):await this.regularAuth()},beforeDestroy(){this.cancelToken&&(this.cancelToken.abort(),this.cancelToken=null)},methods:{...(0,u.nv)("plex",["FETCH_PLEX_INIT_AUTH","REQUEST_PLEX_AUTH_TOKEN","FETCH_PLEX_DEVICES_IF_NEEDED","FETCH_PLEX_USER"]),...(0,u.nv)("plexservers",["FETCH_AND_SET_RANDOM_BACKGROUND_IMAGE"]),...(0,u.OI)("plex",["SET_PLEX_AUTH_TOKEN"]),async regularAuth(){await this.fetchInitialAuthCode()},async cookieAuth(t){this.loading=!0,this.SET_PLEX_AUTH_TOKEN(t);try{await this.FETCH_PLEX_USER(),await this.postAuth(),this.loading=!1}catch(e){console.error(e),this.SET_PLEX_AUTH_TOKEN(null),await this.regularAuth()}},async fetchInitialAuthCode(){this.loading=!0,this.cancelToken=new T.qf.cancelToken,this.plexAuthResponse=await this.FETCH_PLEX_INIT_AUTH(this.cancelToken.signal),this.cancelToken=null,this.loading=!1},async authenticate(){this.loading=!0,this.cancelToken=new T.qf.cancelToken,await this.plexAuthChecker(this.cancelToken.signal),await this.postAuth(),this.loading=!1},redirect(){this.$router.push(this.$route.query.redirect||"/")},async postAuth(){this.redirect(),await this.FETCH_PLEX_DEVICES_IF_NEEDED(),await this.FETCH_AND_SET_RANDOM_BACKGROUND_IMAGE()},plexAuthChecker:(0,T.qf)((function*(t){while(1){yield T.qf.delay(t,this.GET_CONFIG.plex_auth_check_interval);const e=yield this.isAuthComplete(t);if(e)return}})),async isAuthComplete(t){try{return await this.REQUEST_PLEX_AUTH_TOKEN({signal:t,id:this.plexAuthResponse.id}),!0}catch{return!1}}}},U=d;var g=i(1001),I=(0,g.Z)(U,r,E,!1,null,null,null);const C=I.exports}}]);
//# sourceMappingURL=9897.3e3fefb6.js.map