{"ast":null,"code":"import { BehaviorSubject } from 'rxjs';\nimport { environment } from 'src/environments/environment';\nimport * as i0 from \"@angular/core\";\nimport * as i1 from \"@angular/common/http\";\nexport let AuthService = /*#__PURE__*/(() => {\n  class AuthService {\n    constructor(http) {\n      this.http = http;\n      this._apiUrl = environment.apiUrl;\n      this._authenticateUserEndPoint = 'login';\n      this._refreshTokenEndPoint = 'login/refresh';\n      this.tokenData = new BehaviorSubject(null);\n      this.isTokenExist = new BehaviorSubject(this.hasToken());\n      this.tokenizedResponse = environment.apiTokenizationEnabled;\n    }\n\n    AuthenticateUser(params) {\n      let url = `${this._apiUrl}${this._authenticateUserEndPoint}`;\n\n      if (params.mode === 'email') {\n        url += '?m=email';\n      }\n\n      return this.http.post(url, params);\n    }\n\n    RefreshToken(refreshtoken) {\n      const url = `${this._apiUrl}${this._refreshTokenEndPoint}`;\n      return this.http.post(url, {\n        refreshtoken\n      });\n    }\n\n    IsTokenExpired(token) {\n      try {\n        const decoded = this.DecodeToken(token);\n        const now = Math.floor(Date.now() / 1000); // seconds\n\n        return decoded.exp < now;\n      } catch (e) {\n        return true;\n      }\n    }\n\n    DecodeToken(token) {\n      try {\n        const base64Url = token.split('.')[1];\n        const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');\n        const jsonPayload = decodeURIComponent(atob(base64).split('').map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)).join(''));\n        return JSON.parse(jsonPayload);\n      } catch (err) {\n        console.error(\"Failed to decode token\", err);\n        return null;\n      }\n    }\n\n    hasToken() {\n      const tokenString = localStorage.getItem('token');\n\n      if (tokenString) {\n        const tokenData = JSON.parse(tokenString);\n        return (tokenData === null || tokenData === void 0 ? void 0 : tokenData.accesstoken) !== '';\n      }\n\n      return false;\n    }\n\n    SetToken(_tokenData) {\n      localStorage.setItem('token', JSON.stringify(_tokenData));\n      this.tokenData.next(_tokenData);\n      this.isTokenExist.next(true);\n    }\n\n  }\n\n  AuthService.ɵfac = function AuthService_Factory(t) {\n    return new (t || AuthService)(i0.ɵɵinject(i1.HttpClient));\n  };\n\n  AuthService.ɵprov = /*@__PURE__*/i0.ɵɵdefineInjectable({\n    token: AuthService,\n    factory: AuthService.ɵfac,\n    providedIn: 'root'\n  });\n  return AuthService;\n})();","map":null,"metadata":{},"sourceType":"module"}