fix(web,server): web socket auth (for web) (#4632)

This commit is contained in:
Jason Rasmussen
2023-10-24 18:07:24 -04:00
committed by GitHub
parent 3021eca8e5
commit 0fb1d33f17
5 changed files with 39 additions and 24 deletions

View File

@@ -18,7 +18,7 @@
import { handleError } from '$lib/utils/handle-error';
import { dragAndDropFilesStore } from '$lib/stores/drag-and-drop-files.store';
import { api } from '@api';
import { openWebsocketConnection } from '$lib/stores/websocket';
import { closeWebsocketConnection, openWebsocketConnection } from '$lib/stores/websocket';
let showNavigationLoadingBar = false;
export let data: LayoutData;
@@ -28,7 +28,18 @@
api.setKey($page.params.key);
}
beforeNavigate(() => {
beforeNavigate(({ from, to }) => {
const fromRoute = from?.route?.id || '';
const toRoute = to?.route?.id || '';
if (fromRoute.startsWith('/auth') && !toRoute.startsWith('/auth')) {
openWebsocketConnection();
}
if (!fromRoute.startsWith('/auth') && toRoute.startsWith('/auth')) {
closeWebsocketConnection();
}
showNavigationLoadingBar = true;
});
@@ -37,7 +48,9 @@
});
onMount(async () => {
openWebsocketConnection();
if ($page.route.id?.startsWith('/auth') === false) {
openWebsocketConnection();
}
try {
await loadConfig();