Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Logged out of Flagsmith when testing Webhook #2842

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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