Skip to content

Commit

Permalink
fix: use fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Jan 22, 2024
1 parent 3d02733 commit 31e37ce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,10 @@ export default {
// in case of a redirect (302) trigger a page reload
// needed to fix external auth issues #3427
const statusCode = error.response?.status
if ([302, 401].includes(statusCode)) {
if (
[302, 401].includes(statusCode) ||
error.response?.type === 'opaqueredirect'
) {
// reload current page, be sure this doesn't hits cache, add a random query param
location.search = `?auth=${uuid()}`
return
Expand Down
25 changes: 23 additions & 2 deletions src/apis/ConfigApis.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,29 @@ export default {
return request.get('/logout')
},
async isAuthEnabled() {
const response = await request.get('/auth-enabled')
return response.data
// use fetch instead of axios here in order to catch
// redirects and fix external auth:
// https://github.com/zwave-js/zwave-js-ui/issues/3427
// const response = await request.get('/auth-enabled')
// return response.data

const response = await fetch('/api/auth-enabled', {
credentials: 'include',
redirect: 'manual',
headers: {
Accept: 'application/json',
},
})
if (response.type === 'opaqueredirect') {
throw new axios.AxiosError(
'Caught redirect for auth-enabled, rethrowing',
response.status,
response.config,
response.request,
response,
)
}
return await response.json()
},
// ---- USER ------
async updatePassword(data) {
Expand Down

0 comments on commit 31e37ce

Please sign in to comment.