mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
refactor: auth manager (#27638)
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
import { eventManager } from '$lib/managers/event-manager.svelte';
|
||||
import { type UserAdminResponseDto, type UserPreferencesResponseDto } from '@immich/sdk';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const user = writable<UserAdminResponseDto>();
|
||||
export const preferences = writable<UserPreferencesResponseDto>();
|
||||
|
||||
/**
|
||||
* Reset the store to its initial undefined value. Make sure to
|
||||
* only do this _after_ redirecting to an unauthenticated page.
|
||||
*/
|
||||
export const resetSavedUser = () => {
|
||||
user.set(undefined as unknown as UserAdminResponseDto);
|
||||
preferences.set(undefined as unknown as UserPreferencesResponseDto);
|
||||
};
|
||||
|
||||
eventManager.on({
|
||||
AuthLogout: () => resetSavedUser(),
|
||||
});
|
||||
@@ -17,7 +17,6 @@ import {
|
||||
} from '@immich/sdk';
|
||||
import { io, type Socket } from 'socket.io-client';
|
||||
import { get, writable } from 'svelte/store';
|
||||
import { user } from './user.store';
|
||||
|
||||
interface AppRestartEvent {
|
||||
isMaintenanceMode: boolean;
|
||||
@@ -88,7 +87,11 @@ websocket
|
||||
|
||||
export const openWebsocketConnection = () => {
|
||||
try {
|
||||
if (get(user) || get(websocketStore.serverRestarting) || page.url.pathname.startsWith(Route.maintenanceMode())) {
|
||||
if (
|
||||
authManager.authenticated ||
|
||||
get(websocketStore.serverRestarting) ||
|
||||
page.url.pathname.startsWith(Route.maintenanceMode())
|
||||
) {
|
||||
websocket.connect();
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user