refactor: purchase store (#25734)

This commit is contained in:
Jason Rasmussen
2026-02-12 13:32:17 -05:00
committed by GitHub
parent 6c0c4b3dda
commit 5bf4e9595c
9 changed files with 39 additions and 49 deletions
+21 -1
View File
@@ -3,12 +3,31 @@ import { page } from '$app/state';
import { eventManager } from '$lib/managers/event-manager.svelte';
import { Route } from '$lib/route';
import { isSharedLinkRoute } from '$lib/utils/navigation';
import { logout } from '@immich/sdk';
import { getAboutInfo, logout, type UserAdminResponseDto } from '@immich/sdk';
class AuthManager {
isPurchased = $state(false);
isSharedLink = $derived(isSharedLinkRoute(page.route?.id));
params = $derived(this.isSharedLink ? { key: page.params.key, slug: page.params.slug } : {});
constructor() {
eventManager.on({
AuthUserLoaded: (user) => this.onAuthUserLoaded(user),
});
}
private async onAuthUserLoaded(user: UserAdminResponseDto) {
if (user.license?.activatedAt) {
authManager.isPurchased = true;
return;
}
const serverInfo = await getAboutInfo().catch(() => undefined);
if (serverInfo?.licensed) {
authManager.isPurchased = true;
}
}
async logout() {
let redirectUri;
@@ -30,6 +49,7 @@ class AuthManager {
globalThis.location.href = redirectUri;
}
} finally {
this.isPurchased = false;
eventManager.emit('AuthLogout');
}
}