Skip to content

Commit

Permalink
crude attempt to solve #937
Browse files Browse the repository at this point in the history
  • Loading branch information
cstns committed Jun 3, 2024
1 parent 60b4a0e commit 2a3250b
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions ui/src/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,29 @@ const vuetify = createVuetify({

// if our scoket disconnects, we should inform the user when it reconnects

function forcePageReload (err) {
console.log('auth error:', err)
console.log('redirecting to:', window.location.origin + '/dashboard')

// Reloading dashboard without using cache by apending a cache-busting string to fully reload page to allow redirecting to auth
window.location.replace(window.location.origin + '/dashboard' + '?' + 'reloadTime=' + Date.now().toString() + Math.random()) // Seems to work on Edge and Chrome on Windows, Chromium and Firefox on Linux, and also on Chrome Android (and also as PWA App)
}

// GET our SocketIO Config from Node-RED & any other bits plugins have added to the _setup endpoint
fetch('_setup')
.then(async (response) => {
if (
response.url &&
typeof response.url === 'string' &&
!response.url.includes( new URL(window.location).origin)) {

Check failure on line 80 in ui/src/main.mjs

View workflow job for this annotation

GitHub Actions / build / build (16.x)

There should be no space after this paren

Check failure on line 80 in ui/src/main.mjs

View workflow job for this annotation

GitHub Actions / build / build (16.x)

Block must not be padded by blank lines

// todo not sure if we should force redirect or just stop the setup process entirely
// forcePageReload('origins do not match')

return;

Check failure on line 85 in ui/src/main.mjs

View workflow job for this annotation

GitHub Actions / build / build (16.x)

Extra semicolon
}

console.log('_setup', response, typeof response.url === 'string')
const url = new URL(response.url)
const basePath = url.pathname.replace('/_setup', '')

Expand Down Expand Up @@ -168,14 +188,7 @@ fetch('_setup')
.catch((err) => {
if (err instanceof TypeError) {
if (err.message === 'Failed to fetch') {
console.log('auth error:', err)
console.log('redirecting to:', window.location.origin + '/dashboard')

// window.location.replace(window.location.origin + '/dashboard') //Original, seems to have no issues with Edge and Chrome on Windows, doesn't work on Android (Not tested on Linux browser)
// window.location.href = window.location.origin + window.location.pathname + window.location.search + (window.location.search ? '&' : '?') + 'reloadTime=' + Date.now().toString() + window.location.hash; // Also works on Edge + Chrome on windows, doesn't work on android

// Reloading dashboard without using cache by apending a cache-busting string to fully reload page to allow redirecting to auth
window.location.replace(window.location.origin + '/dashboard' + '?' + 'reloadTime=' + Date.now().toString() + Math.random()) // Seems to work on Edge and Chrome on Windows, Chromium and Firefox on Linux, and also on Chrome Android (and also as PWA App)
forcePageReload(err)
} else {
// handle general Type errors here
console.error('An error occurred:', err)
Expand Down

0 comments on commit 2a3250b

Please sign in to comment.