0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-02-11 01:18:24 -05:00

fix(web): websocket reconnect (#7234)

* fix(web): websocket reconnect

* reset store after navigation completes

* remove loggedOut check
This commit is contained in:
Michel Heusschen 2024-02-20 15:20:09 +01:00 committed by GitHub
parent 7f5459f050
commit e7a875eadd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 21 deletions

View file

@ -29,13 +29,13 @@
}>(); }>();
const logOut = async () => { const logOut = async () => {
resetSavedUser();
const { redirectUri } = await logout(); const { redirectUri } = await logout();
if (redirectUri.startsWith('/')) { if (redirectUri.startsWith('/')) {
goto(redirectUri); await goto(redirectUri);
} else { } else {
window.location.href = redirectUri; window.location.href = redirectUri;
} }
resetSavedUser();
}; };
</script> </script>

View file

@ -1,8 +1,12 @@
import type { UserResponseDto } from '@immich/sdk'; import type { UserResponseDto } from '@immich/sdk';
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
export let user = writable<UserResponseDto>(); export const user = writable<UserResponseDto>();
/**
* Reset the store to its initial undefined value. Make sure to
* only do this _after_ redirecting to an unauthenticated page.
*/
export const resetSavedUser = () => { export const resetSavedUser = () => {
user = writable<UserResponseDto>(); user.set(undefined as unknown as UserResponseDto);
}; };

View file

@ -22,10 +22,15 @@
let albumId: string | undefined; let albumId: string | undefined;
const isSharedLinkRoute = (route: string | null) => route?.startsWith('/(user)/share/[key]'); const isSharedLinkRoute = (route: string | null) => route?.startsWith('/(user)/share/[key]');
const isAuthRoute = (route?: string) => route?.startsWith('/auth');
$: changeTheme($colorTheme); $: changeTheme($colorTheme);
$: if ($user) {
openWebsocketConnection();
} else {
closeWebsocketConnection();
}
const changeTheme = (theme: ThemeSetting) => { const changeTheme = (theme: ThemeSetting) => {
if (theme.system) { if (theme.system) {
theme.value = theme.value =
@ -58,18 +63,7 @@
setKey($page.params.key); setKey($page.params.key);
} }
beforeNavigate(({ from, to }) => { beforeNavigate(() => {
const fromRoute = from?.route?.id || '';
const toRoute = to?.route?.id || '';
if (isAuthRoute(fromRoute) && !isAuthRoute(toRoute)) {
openWebsocketConnection();
}
if (!isAuthRoute(fromRoute) && isAuthRoute(toRoute)) {
closeWebsocketConnection();
}
showNavigationLoadingBar = true; showNavigationLoadingBar = true;
}); });
@ -78,10 +72,6 @@
}); });
onMount(async () => { onMount(async () => {
if ($page.route.id?.startsWith('/auth') === false) {
openWebsocketConnection();
}
try { try {
await loadConfig(); await loadConfig();
} catch (error) { } catch (error) {