From 712d9f264ccad4134aa9242c44e24c4792cdedc3 Mon Sep 17 00:00:00 2001 From: Greg Hogan Date: Wed, 29 Nov 2023 13:53:12 -0800 Subject: [PATCH] fix unauthorizedHandler param --- dist/instance.js | 7 +++++-- src/instance.js | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dist/instance.js b/dist/instance.js index 2ce4a68..23abe7e 100644 --- a/dist/instance.js +++ b/dist/instance.js @@ -29,20 +29,23 @@ export var RequestError = /*#__PURE__*/function (_Error) { }( /*#__PURE__*/_wrapNativeSuper(Error)); var ConfigRequest = /*#__PURE__*/function () { function ConfigRequest(baseUrl) { - var unauthorizedHandler = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; _classCallCheck(this, ConfigRequest); this.defaultHeaders = { 'Content-Type': 'application/json' }; this.baseUrl = baseUrl + (!baseUrl.endsWith('/') ? '/' : ''); - this.unauthorizedHandler = unauthorizedHandler; + this.unauthorizedHandler = null; } _createClass(ConfigRequest, [{ key: "configure", value: function configure(accessToken) { + var unauthorizedHandler = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; if (accessToken) { this.defaultHeaders.Authorization = "JWT ".concat(accessToken); } + if (unauthorizedHandler) { + this.unauthorizedHandler = unauthorizedHandler; + } } }, { key: "request", diff --git a/src/instance.js b/src/instance.js index 0671a93..df49b6f 100644 --- a/src/instance.js +++ b/src/instance.js @@ -9,18 +9,21 @@ export class RequestError extends Error { } export default class ConfigRequest { - constructor(baseUrl, unauthorizedHandler = null) { + constructor(baseUrl) { this.defaultHeaders = { 'Content-Type': 'application/json', }; this.baseUrl = baseUrl + (!baseUrl.endsWith('/') ? '/' : ''); - this.unauthorizedHandler = unauthorizedHandler; + this.unauthorizedHandler = null; } - configure(accessToken) { + configure(accessToken, unauthorizedHandler = null) { if (accessToken) { this.defaultHeaders.Authorization = `JWT ${accessToken}`; } + if (unauthorizedHandler) { + this.unauthorizedHandler = unauthorizedHandler; + } } async request(method, endpoint, params, dataJson = true, respJson = true) {