Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): websocket reconnect #7234

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions web/src/lib/stores/user.store.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import type { UserResponseDto } from '@immich/sdk';
import { writable } from 'svelte/store';

export let user = writable<UserResponseDto>();
export const user = writable<UserResponseDto & { loggedOut?: true }>();

export const resetSavedUser = () => {
user = writable<UserResponseDto>();
user.update((value) => {
if (value) {
value.loggedOut = true;
}
return value;
});
};
2 changes: 1 addition & 1 deletion web/src/lib/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface AuthOptions {
export const loadUser = async () => {
try {
let loaded = get(user);
if (!loaded && hasAuthCookie()) {
if ((!loaded || loaded?.loggedOut) && hasAuthCookie()) {
loaded = await getMyUserInfo();
user.set(loaded);
}
Expand Down
24 changes: 7 additions & 17 deletions web/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 || $user?.loggedOut) {
closeWebsocketConnection();
} else if ($user) {
openWebsocketConnection();
}

const changeTheme = (theme: ThemeSetting) => {
if (theme.system) {
theme.value =
Expand Down Expand Up @@ -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;
});

Expand All @@ -78,10 +72,6 @@
});

onMount(async () => {
if ($page.route.id?.startsWith('/auth') === false) {
openWebsocketConnection();
}

try {
await loadConfig();
} catch (error) {
Expand Down
Loading