Skip to content

Commit

Permalink
fix(ui): ignore **/api/** from service worker cache (#3519)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Jan 23, 2024
1 parent b1a34df commit 2b7d53c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ typings/
!.yarn/sdks
!.yarn/versions

.vite

fakeNodes.json

/build/
12 changes: 12 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ import {
InclusionState,
} from 'zwave-js/safe'
import DialogNodesManager from '@/components/dialogs/DialogNodesManager.vue'
import { uuid } from './lib/utils'
let socketQueue = []
Expand Down Expand Up @@ -1124,6 +1125,17 @@ export default {
this.startSocket()
}
} catch (error) {
// 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) ||
error.response?.type === 'opaqueredirect'
) {
// reload current page, be sure this doesn't hits cache, add a random query param
location.search = `?auth=${uuid()}`
return
}
setTimeout(() => (this.error = error.message), 1000)
log.error(error)
}
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
3 changes: 3 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export default defineConfig(({ mode }) => {
type: 'module',
/* other options */
},
workbox: {
globIgnores: ['**/api/**'],
},
manifest: {
name: process.env.VITE_TITLE,
description: process.env.VITE_TITLE,
Expand Down

0 comments on commit 2b7d53c

Please sign in to comment.