mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
fix(web): websocket reconnect (#7234)
* fix(web): websocket reconnect * reset store after navigation completes * remove loggedOut check
This commit is contained in:
parent
7f5459f050
commit
e7a875eadd
3 changed files with 15 additions and 21 deletions
|
@ -29,13 +29,13 @@
|
|||
}>();
|
||||
|
||||
const logOut = async () => {
|
||||
resetSavedUser();
|
||||
const { redirectUri } = await logout();
|
||||
if (redirectUri.startsWith('/')) {
|
||||
goto(redirectUri);
|
||||
await goto(redirectUri);
|
||||
} else {
|
||||
window.location.href = redirectUri;
|
||||
}
|
||||
resetSavedUser();
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import type { UserResponseDto } from '@immich/sdk';
|
||||
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 = () => {
|
||||
user = writable<UserResponseDto>();
|
||||
user.set(undefined as unknown as UserResponseDto);
|
||||
};
|
||||
|
|
|
@ -22,10 +22,15 @@
|
|||
let albumId: string | undefined;
|
||||
|
||||
const isSharedLinkRoute = (route: string | null) => route?.startsWith('/(user)/share/[key]');
|
||||
const isAuthRoute = (route?: string) => route?.startsWith('/auth');
|
||||
|
||||
$: changeTheme($colorTheme);
|
||||
|
||||
$: if ($user) {
|
||||
openWebsocketConnection();
|
||||
} else {
|
||||
closeWebsocketConnection();
|
||||
}
|
||||
|
||||
const changeTheme = (theme: ThemeSetting) => {
|
||||
if (theme.system) {
|
||||
theme.value =
|
||||
|
@ -58,18 +63,7 @@
|
|||
setKey($page.params.key);
|
||||
}
|
||||
|
||||
beforeNavigate(({ from, to }) => {
|
||||
const fromRoute = from?.route?.id || '';
|
||||
const toRoute = to?.route?.id || '';
|
||||
|
||||
if (isAuthRoute(fromRoute) && !isAuthRoute(toRoute)) {
|
||||
openWebsocketConnection();
|
||||
}
|
||||
|
||||
if (!isAuthRoute(fromRoute) && isAuthRoute(toRoute)) {
|
||||
closeWebsocketConnection();
|
||||
}
|
||||
|
||||
beforeNavigate(() => {
|
||||
showNavigationLoadingBar = true;
|
||||
});
|
||||
|
||||
|
@ -78,10 +72,6 @@
|
|||
});
|
||||
|
||||
onMount(async () => {
|
||||
if ($page.route.id?.startsWith('/auth') === false) {
|
||||
openWebsocketConnection();
|
||||
}
|
||||
|
||||
try {
|
||||
await loadConfig();
|
||||
} catch (error) {
|
||||
|
|
Loading…
Reference in a new issue