Skip to content

Commit

Permalink
fix unauthorizedHandler param
Browse files Browse the repository at this point in the history
  • Loading branch information
gregjhogan committed Nov 29, 2023
1 parent c340e70 commit 712d9f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions dist/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 6 additions & 3 deletions src/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 712d9f2

Please sign in to comment.