From cfbf7f192e699c9318c97a05266e31ff7d680e3d Mon Sep 17 00:00:00 2001 From: Novak Zaballa <41410593+novakzaballa@users.noreply.github.com> Date: Mon, 16 Oct 2023 09:56:51 -0400 Subject: [PATCH] fix: Logged out of Flagsmith when testing Webhook (#2842) --- frontend/common/data/base/_data.js | 17 ++++++++++------- frontend/web/components/TestWebhook.tsx | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/frontend/common/data/base/_data.js b/frontend/common/data/base/_data.js index fc1ff8947de5..c1613a07fd5b 100644 --- a/frontend/common/data/base/_data.js +++ b/frontend/common/data/base/_data.js @@ -6,7 +6,7 @@ const getQueryString = (params) => { } module.exports = { - _request(method, _url, data, headers = {}) { + _request(method, _url, data, headers = {}, isExternal) { const options = { headers: { 'Accept': 'application/json', @@ -19,7 +19,10 @@ module.exports = { if (method !== 'get') options.headers['Content-Type'] = 'application/json; charset=utf-8' - if (this.token) { + if ( + (this.token && !isExternal) || + (this.token && isExternal && method !== 'get') + ) { // add auth tokens to headers of all requests options.headers.AUTHORIZATION = `Token ${this.token}` } @@ -51,7 +54,7 @@ module.exports = { } return fetch(url, options) - .then(this.status) + .then((response) => this.status(response, isExternal)) .then((response) => { // always return json let contentType = response.headers.get('content-type') @@ -75,8 +78,8 @@ module.exports = { return this._request('get', url, data || null, headers) }, - post(url, data, headers) { - return this._request('post', url, data, headers) + post(url, data, headers, isExternal = false) { + return this._request('post', url, data, headers, isExternal) }, put(url, data, headers) { @@ -88,12 +91,12 @@ module.exports = { this.token = _token }, - status(response) { + status(response, isExternal) { // handle ajax requests if (response.status >= 200 && response.status < 300) { return Promise.resolve(response) } - if (response.status === 401) { + if (!isExternal && response.status === 401) { AppActions.setUser(null) } response diff --git a/frontend/web/components/TestWebhook.tsx b/frontend/web/components/TestWebhook.tsx index c1379e57fef8..bc287548ee0b 100644 --- a/frontend/web/components/TestWebhook.tsx +++ b/frontend/web/components/TestWebhook.tsx @@ -19,7 +19,7 @@ const TestWebhook: FC = ({ json, webhook }) => { setLoading(true) setSuccess(false) data - .post(webhook, JSON.parse(json)) + .post(webhook, JSON.parse(json), null, true) .then(() => { setLoading(false) setSuccess(true)