diff --git a/.gitignore b/.gitignore index a1243acede6..b21650280d8 100644 --- a/.gitignore +++ b/.gitignore @@ -84,6 +84,8 @@ typings/ !.yarn/sdks !.yarn/versions +.vite + fakeNodes.json /build/ \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 611b1a7b4a0..60faeefe249 100644 --- a/src/App.vue +++ b/src/App.vue @@ -416,6 +416,7 @@ import { InclusionState, } from 'zwave-js/safe' import DialogNodesManager from '@/components/dialogs/DialogNodesManager.vue' +import { uuid } from './lib/utils' let socketQueue = [] @@ -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) } diff --git a/src/apis/ConfigApis.js b/src/apis/ConfigApis.js index 1d830b7f14d..ecade4e7750 100644 --- a/src/apis/ConfigApis.js +++ b/src/apis/ConfigApis.js @@ -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) { diff --git a/vite.config.js b/vite.config.js index 645e7603cbc..6b1a913ea17 100644 --- a/vite.config.js +++ b/vite.config.js @@ -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,