UNPKG

architect-sdk

Version:

Essentialz Architect SDK

44 lines (43 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TokenManager = void 0; var TokenManager = /** @class */ (function () { function TokenManager(tokenKey, userIdKey) { this.tokenKey = tokenKey; this.userIdKey = userIdKey; this.token = localStorage.getItem(this.tokenKey); this.userId = localStorage.getItem(this.userIdKey); } TokenManager.getInstance = function (tokenKey, userIdKey) { if (!TokenManager.instance) { TokenManager.instance = new TokenManager(tokenKey, userIdKey); } return TokenManager.instance; }; TokenManager.prototype.setToken = function (token) { this.token = token; if (token) { localStorage.setItem(this.tokenKey, token); } else { localStorage.removeItem(this.tokenKey); } }; TokenManager.prototype.getToken = function () { return this.token; }; TokenManager.prototype.getUserId = function () { return this.userId; }; TokenManager.prototype.setUserId = function (id) { this.userId = id; if (id) { localStorage.setItem(this.userIdKey, id); } else { localStorage.removeItem(this.userIdKey); } }; return TokenManager; }()); exports.TokenManager = TokenManager;