Skip to content

Commit

Permalink
fix: Logged out of Flagsmith when testing Webhook (#2842)
Browse files Browse the repository at this point in the history
  • Loading branch information
novakzaballa authored Oct 16, 2023
1 parent 619c3f5 commit cfbf7f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions frontend/common/data/base/_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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}`
}
Expand Down Expand Up @@ -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')
Expand All @@ -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) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/components/TestWebhook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const TestWebhook: FC<TestWebhookType> = ({ json, webhook }) => {
setLoading(true)
setSuccess(false)
data
.post(webhook, JSON.parse(json))
.post(webhook, JSON.parse(json), null, true)
.then(() => {
setLoading(false)
setSuccess(true)
Expand Down

3 comments on commit cfbf7f1

@vercel
Copy link

@vercel vercel bot commented on cfbf7f1 Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs.flagsmith.com
docs-flagsmith.vercel.app
docs.bullet-train.io
docs-git-main-flagsmith.vercel.app

@vercel
Copy link

@vercel vercel bot commented on cfbf7f1 Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on cfbf7f1 Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.