Skip to content

Commit 3b50d87

Browse files
committed
refactor: auth manager
1 parent b5bed02 commit 3b50d87

File tree

77 files changed

+386
-378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+386
-378
lines changed

web/src/lib/components/VersionAnnouncement.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import OnEvents from '$lib/components/OnEvents.svelte';
3+
import { authManager } from '$lib/managers/auth-manager.svelte';
34
import VersionAnnouncementModal from '$lib/modals/VersionAnnouncementModal.svelte';
4-
import { user } from '$lib/stores/user.store';
55
import type { ReleaseEvent } from '$lib/types';
66
import { getReleaseType, semverToName } from '$lib/utils';
77
import { modalManager } from '@immich/ui';
@@ -12,7 +12,7 @@
1212
}>();
1313
1414
const onReleaseEvent = async (release: ReleaseEvent) => {
15-
if (!release.isAvailable || !$user.isAdmin) {
15+
if (!release.isAvailable || !authManager.user.isAdmin) {
1616
return;
1717
}
1818

web/src/lib/components/admin-settings/NotificationSettings.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import SettingSwitch from '$lib/components/shared-components/settings/setting-switch.svelte';
66
import SettingButtonsRow from '$lib/components/shared-components/settings/SystemConfigButtonRow.svelte';
77
import { SettingInputFieldType } from '$lib/constants';
8+
import { authManager } from '$lib/managers/auth-manager.svelte';
89
import { featureFlagsManager } from '$lib/managers/feature-flags-manager.svelte';
910
import { systemConfigManager } from '$lib/managers/system-config-manager.svelte';
1011
import { handleSystemConfigSave } from '$lib/services/system-config.service';
11-
import { user } from '$lib/stores/user.store';
1212
import { handleError } from '$lib/utils/handle-error';
1313
import { sendTestEmailAdmin } from '@immich/sdk';
1414
import { Button, toastManager } from '@immich/ui';
@@ -45,7 +45,9 @@
4545
},
4646
});
4747
48-
toastManager.primary($t('admin.notification_email_test_email_sent', { values: { email: $user.email } }));
48+
toastManager.primary(
49+
$t('admin.notification_email_test_email_sent', { values: { email: authManager.user.email } }),
50+
);
4951
5052
if (!disabled) {
5153
await handleSystemConfigSave({ notifications: configToEdit.notifications });

web/src/lib/components/admin-settings/StorageTemplateSettings.svelte

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import SettingSwitch from '$lib/components/shared-components/settings/setting-switch.svelte';
77
import { SettingInputFieldType } from '$lib/constants';
88
import FormatMessage from '$lib/elements/FormatMessage.svelte';
9+
import { authManager } from '$lib/managers/auth-manager.svelte';
910
import { featureFlagsManager } from '$lib/managers/feature-flags-manager.svelte';
1011
import { systemConfigManager } from '$lib/managers/system-config-manager.svelte';
1112
import { Route } from '$lib/route';
1213
import { handleSystemConfigSave } from '$lib/services/system-config.service';
13-
import { user } from '$lib/stores/user.store';
1414
import { getStorageTemplateOptions, type SystemConfigTemplateStorageOptionDto } from '@immich/sdk';
1515
import { Heading, Link, LoadingSpinner, Text } from '@immich/ui';
1616
import handlebar from 'handlebars';
@@ -177,7 +177,10 @@
177177
<p class="text-sm">
178178
<FormatMessage
179179
key="admin.storage_template_path_length"
180-
values={{ length: parsedTemplate().length + $user.id.length + 'UPLOAD_LOCATION'.length, limit: 260 }}
180+
values={{
181+
length: parsedTemplate().length + authManager.user.id.length + 'UPLOAD_LOCATION'.length,
182+
limit: 260,
183+
}}
181184
>
182185
{#snippet children({ message })}
183186
<span class="font-semibold text-primary">{message}</span>
@@ -186,7 +189,10 @@
186189
</p>
187190

188191
<p class="text-sm">
189-
<FormatMessage key="admin.storage_template_user_label" values={{ label: $user.storageLabel || $user.id }}>
192+
<FormatMessage
193+
key="admin.storage_template_user_label"
194+
values={{ label: authManager.user.storageLabel || authManager.user.id }}
195+
>
190196
{#snippet children({ message })}
191197
<code class="text-primary">{message}</code>
192198
{/snippet}
@@ -195,7 +201,7 @@
195201

196202
<p class="p-4 py-2 mt-2 text-xs bg-gray-200 rounded-lg dark:bg-gray-700 dark:text-immich-dark-fg">
197203
<span class="text-immich-fg/25 dark:text-immich-dark-fg/50"
198-
>UPLOAD_LOCATION/library/{$user.storageLabel || $user.id}</span
204+
>UPLOAD_LOCATION/library/{authManager.user.storageLabel || authManager.user.id}</span
199205
>/{parsedTemplate()}.jpg
200206
</p>
201207

web/src/lib/components/album-page/album-card.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import AlbumCover from '$lib/components/album-page/album-cover.svelte';
3-
import { user } from '$lib/stores/user.store';
3+
import { authManager } from '$lib/managers/auth-manager.svelte';
44
import { getContextMenuPositionFromEvent, type ContextMenuPosition } from '$lib/utils/context-menu';
55
import { getShortDateRange } from '$lib/utils/date-time';
66
import type { AlbumResponseDto } from '@immich/sdk';
@@ -85,7 +85,7 @@
8585
{/if}
8686

8787
{#if showOwner}
88-
{#if $user.id === album.ownerId}
88+
{#if authManager.user.id === album.ownerId}
8989
<p>{$t('owned')}</p>
9090
{:else if album.owner}
9191
<p>{$t('shared_by_user', { values: { user: album.owner.name } })}</p>

web/src/lib/components/album-page/albums-list.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import OnEvents from '$lib/components/OnEvents.svelte';
55
import MenuOption from '$lib/components/shared-components/context-menu/menu-option.svelte';
66
import RightClickContextMenu from '$lib/components/shared-components/context-menu/right-click-context-menu.svelte';
7+
import { authManager } from '$lib/managers/auth-manager.svelte';
78
import AlbumEditModal from '$lib/modals/AlbumEditModal.svelte';
89
import AlbumOptionsModal from '$lib/modals/AlbumOptionsModal.svelte';
910
import { handleDeleteAlbum, handleDownloadAlbum } from '$lib/services/album.service';
@@ -16,7 +17,6 @@
1617
SortOrder,
1718
type AlbumViewSettings,
1819
} from '$lib/stores/preferences.store';
19-
import { user } from '$lib/stores/user.store';
2020
import { getSelectedAlbumGroupOption, sortAlbums, stringToSortOrder, type AlbumGroup } from '$lib/utils/album-utils';
2121
import type { ContextMenuPosition } from '$lib/utils/context-menu';
2222
import { normalizeSearchString } from '$lib/utils/string-utils';
@@ -97,7 +97,7 @@
9797
9898
/** Group by owner */
9999
[AlbumGroupBy.Owner]: (order, albums): AlbumGroup[] => {
100-
const currentUserId = $user.id;
100+
const currentUserId = authManager.user.id;
101101
const groupedByOwnerIds = groupBy(albums, 'ownerId');
102102
103103
const sortSign = order === SortOrder.Desc ? -1 : 1;
@@ -130,7 +130,7 @@
130130
return sharedAlbums;
131131
}
132132
default: {
133-
const nonOwnedAlbums = sharedAlbums.filter((album) => album.ownerId !== $user.id);
133+
const nonOwnedAlbums = sharedAlbums.filter((album) => album.ownerId !== authManager.user.id);
134134
return nonOwnedAlbums.length > 0 ? ownedAlbums.concat(nonOwnedAlbums) : ownedAlbums;
135135
}
136136
}
@@ -167,7 +167,7 @@
167167
albumGroupIds = groupedAlbums.map(({ id }) => id);
168168
});
169169
170-
let showFullContextMenu = $derived(allowEdit && selectedAlbum && selectedAlbum.ownerId === $user.id);
170+
let showFullContextMenu = $derived(allowEdit && selectedAlbum && selectedAlbum.ownerId === authManager.user.id);
171171
172172
onMount(async () => {
173173
if (allowEdit) {

web/src/lib/components/album-page/albums-table-row.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<script lang="ts">
22
import { goto } from '$app/navigation';
33
import { dateFormats } from '$lib/constants';
4+
import { authManager } from '$lib/managers/auth-manager.svelte';
45
import { Route } from '$lib/route';
56
import { locale } from '$lib/stores/preferences.store';
6-
import { user } from '$lib/stores/user.store';
77
import type { ContextMenuPosition } from '$lib/utils/context-menu';
88
import type { AlbumResponseDto } from '@immich/sdk';
99
import { Icon } from '@immich/ui';
@@ -43,7 +43,7 @@
4343
icon={mdiShareVariantOutline}
4444
size="16"
4545
class="inline ms-1 opacity-70"
46-
title={album.ownerId === $user.id
46+
title={album.ownerId === authManager.user.id
4747
? $t('shared_by_you')
4848
: $t('shared_by_user', { values: { user: album.owner.name } })}
4949
/>

web/src/lib/components/asset-viewer/actions/rating-action.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { shortcuts } from '$lib/actions/shortcut';
33
import type { OnAction } from '$lib/components/asset-viewer/actions/action';
44
import { AssetAction } from '$lib/constants';
5-
import { preferences } from '$lib/stores/user.store';
5+
import { authManager } from '$lib/managers/auth-manager.svelte';
66
import { handleError } from '$lib/utils/handle-error';
77
import { toTimelineAsset } from '$lib/utils/timeline-util';
88
import { updateAsset, type AssetResponseDto } from '@immich/sdk';
@@ -42,7 +42,7 @@
4242
</script>
4343

4444
<svelte:document
45-
use:shortcuts={$preferences?.ratings.enabled
45+
use:shortcuts={authManager.authenticated && authManager.preferences.ratings.enabled
4646
? [
4747
{ shortcut: { key: '0' }, onShortcut: () => rateAsset(null) },
4848
...[1, 2, 3, 4, 5].map((rating) => ({

web/src/lib/components/asset-viewer/activity-viewer.svelte

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import { timeBeforeShowLoadingSpinner } from '$lib/constants';
66
import { activityManager } from '$lib/managers/activity-manager.svelte';
77
import { assetViewerManager } from '$lib/managers/asset-viewer-manager.svelte';
8+
import { authManager } from '$lib/managers/auth-manager.svelte';
89
import { Route } from '$lib/route';
910
import { locale } from '$lib/stores/preferences.store';
1011
import { getAssetMediaUrl } from '$lib/utils';
1112
import { getAssetType } from '$lib/utils/asset-utils';
1213
import { handleError } from '$lib/utils/handle-error';
1314
import { isTenMinutesApart } from '$lib/utils/timesince';
14-
import { ReactionType, type ActivityResponseDto, type AssetTypeEnum, type UserResponseDto } from '@immich/sdk';
15+
import { ReactionType, type ActivityResponseDto, type AssetTypeEnum } from '@immich/sdk';
1516
import { Icon, IconButton, LoadingSpinner, Textarea, toastManager } from '@immich/ui';
1617
import { mdiClose, mdiDeleteOutline, mdiDotsVertical, mdiSend, mdiThumbUp } from '@mdi/js';
1718
import * as luxon from 'luxon';
@@ -39,15 +40,14 @@
3940
};
4041
4142
interface Props {
42-
user: UserResponseDto;
4343
assetId?: string | undefined;
4444
albumId: string;
4545
assetType?: AssetTypeEnum | undefined;
4646
albumOwnerId: string;
4747
disabled: boolean;
4848
}
4949
50-
let { user, assetId = undefined, albumId, assetType = undefined, albumOwnerId, disabled }: Props = $props();
50+
let { assetId = undefined, albumId, assetType = undefined, albumOwnerId, disabled }: Props = $props();
5151
5252
let innerHeight: number = $state(0);
5353
let activityHeight: number = $state(0);
@@ -147,7 +147,7 @@
147147
/>
148148
</a>
149149
{/if}
150-
{#if reaction.user.id === user.id || albumOwnerId === user.id}
150+
{#if reaction.user.id === authManager.user.id || albumOwnerId === authManager.user.id}
151151
<div class="me-4">
152152
<ButtonContextMenu
153153
icon={mdiDotsVertical}
@@ -200,7 +200,7 @@
200200
/>
201201
</a>
202202
{/if}
203-
{#if reaction.user.id === user.id || albumOwnerId === user.id}
203+
{#if reaction.user.id === authManager.user.id || albumOwnerId === authManager.user.id}
204204
<div class="me-4">
205205
<ButtonContextMenu
206206
icon={mdiDotsVertical}
@@ -238,7 +238,7 @@
238238
<div class="flex items-center justify-center p-2" bind:clientHeight={chatHeight}>
239239
<div class="flex p-2 gap-4 h-fit bg-gray-200 text-immich-dark-gray rounded-3xl w-full">
240240
<div>
241-
<UserAvatar {user} size="md" noTitle />
241+
<UserAvatar user={authManager.user} size="md" noTitle />
242242
</div>
243243
<form class="flex w-full items-center max-h-56 gap-1" {onsubmit}>
244244
<Textarea

web/src/lib/components/asset-viewer/asset-viewer-nav-bar.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getResizeObserverMock } from '$lib/__mocks__/resize-observer.mock';
2-
import { preferences as preferencesStore, resetSavedUser, user as userStore } from '$lib/stores/user.store';
2+
import { authManager } from '$lib/managers/auth-manager.svelte';
33
import { renderWithTooltips } from '$tests/helpers';
44
import { assetFactory } from '@test-data/factories/asset-factory';
55
import { preferencesFactory } from '@test-data/factories/preferences-factory';
@@ -36,16 +36,16 @@ describe('AssetViewerNavBar component', () => {
3636
});
3737

3838
afterEach(() => {
39-
resetSavedUser();
39+
authManager.reset();
4040
});
4141

4242
afterAll(() => {
4343
vi.restoreAllMocks();
4444
});
4545

4646
it('shows back button', () => {
47-
const prefs = preferencesFactory.build({ cast: { gCastEnabled: false } });
48-
preferencesStore.set(prefs);
47+
const preferences = preferencesFactory.build({ cast: { gCastEnabled: false } });
48+
authManager.setPreferences(preferences);
4949

5050
const asset = assetFactory.build({ isTrashed: false });
5151
const { getByLabelText } = renderWithTooltips(AssetViewerNavBar, { asset, ...additionalProps });
@@ -57,10 +57,10 @@ describe('AssetViewerNavBar component', () => {
5757
const ownerId = 'id-of-the-user';
5858
const user = userAdminFactory.build({ id: ownerId });
5959
const asset = assetFactory.build({ ownerId, isTrashed: false });
60-
userStore.set(user);
60+
authManager.setUser(user);
6161

62-
const prefs = preferencesFactory.build({ cast: { gCastEnabled: false } });
63-
preferencesStore.set(prefs);
62+
const preferences = preferencesFactory.build({ cast: { gCastEnabled: false } });
63+
authManager.setPreferences(preferences);
6464

6565
const { getByLabelText } = renderWithTooltips(AssetViewerNavBar, { asset, ...additionalProps });
6666
expect(getByLabelText('delete')).toBeInTheDocument();

web/src/lib/components/asset-viewer/asset-viewer-nav-bar.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import KeepThisDeleteOthersAction from '$lib/components/asset-viewer/actions/keep-this-delete-others.svelte';
99
import RatingAction from '$lib/components/asset-viewer/actions/rating-action.svelte';
1010
import RemoveAssetFromStack from '$lib/components/asset-viewer/actions/remove-asset-from-stack.svelte';
11-
import RemoveFromAlbumAction from '$lib/components/timeline/actions/RemoveFromAlbumAction.svelte';
1211
import RestoreAction from '$lib/components/asset-viewer/actions/restore-action.svelte';
1312
import SetAlbumCoverAction from '$lib/components/asset-viewer/actions/set-album-cover-action.svelte';
1413
import SetFeaturedPhotoAction from '$lib/components/asset-viewer/actions/set-person-featured-action.svelte';
@@ -19,13 +18,14 @@
1918
import LoadingDots from '$lib/components/LoadingDots.svelte';
2019
import ButtonContextMenu from '$lib/components/shared-components/context-menu/button-context-menu.svelte';
2120
import MenuOption from '$lib/components/shared-components/context-menu/menu-option.svelte';
21+
import RemoveFromAlbumAction from '$lib/components/timeline/actions/RemoveFromAlbumAction.svelte';
2222
import { assetViewerManager } from '$lib/managers/asset-viewer-manager.svelte';
23+
import { authManager } from '$lib/managers/auth-manager.svelte';
2324
import { featureFlagsManager } from '$lib/managers/feature-flags-manager.svelte';
2425
import { languageManager } from '$lib/managers/language-manager.svelte';
2526
import { Route } from '$lib/route';
2627
import { getGlobalActions } from '$lib/services/app.service';
2728
import { getAssetActions } from '$lib/services/asset.service';
28-
import { user } from '$lib/stores/user.store';
2929
import { getSharedLink, withoutIcons } from '$lib/utils';
3030
import type { OnUndoDelete } from '$lib/utils/actions';
3131
import { toTimelineAsset } from '$lib/utils/timeline-util';
@@ -81,8 +81,8 @@
8181
setPlayOriginalVideo,
8282
}: Props = $props();
8383
84-
const isOwner = $derived($user && asset.ownerId === $user?.id);
85-
const isAlbumOwner = $derived($user && album?.ownerId === $user?.id);
84+
const isOwner = $derived(authManager.authenticated && asset.ownerId === authManager.user.id);
85+
const isAlbumOwner = $derived(authManager.authenticated && album?.ownerId === authManager.user.id);
8686
const isLocked = $derived(asset.visibility === AssetVisibility.Locked);
8787
const smartSearchEnabled = $derived(featureFlagsManager.value.smartSearch);
8888

0 commit comments

Comments
 (0)