import e from"@babel/runtime/helpers/asyncToGenerator";import r from"@babel/runtime/helpers/classCallCheck";import t from"@babel/runtime/helpers/createClass";import n from"@babel/runtime/helpers/defineProperty";import i from"@babel/runtime/regenerator";import{refreshToken as o}from"./apiCore.js";var s=function(){function s(){r(this,s),n(this,"refreshPromise",null),n(this,"refreshFn",void 0),this.refreshFn=o}var a;return t(s,[{key:"tryRefresh",value:(a=e(i.mark((function e(){var r=this;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.refreshPromise||(this.refreshPromise=this.refreshFn().finally((function(){r.refreshPromise=null}))),e.abrupt("return",this.refreshPromise);case 2:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"isRefreshableAuthError",value:function(e){var r,t;return null!==(r=null===(t=e.isAuthenticationProblem)||void 0===t?void 0:t.call(e))&&void 0!==r&&r&&!e.isTermsProblem()&&!e.isLoginProblem()}},{key:"handleAuthFailure",value:function(e){this.isRefreshableAuthError(e)&&(console.error("Unrecoverable authentication failure detected;"),window.location.pathname.startsWith("/login")||(console.error("Redirecting to /login."),window.location.href="/login"))}}],[{key:"getInstance",value:function(){return s.instance||(s.instance=new s),s.instance}}]),s}();n(s,"instance",void 0);export{s as AuthRecovery};
//# sourceMappingURL=AuthRecovery.js.map
