Skip to content

Commit 9e0baf6

Browse files
committed
fix(watching): adds auth check before polling
1 parent 35d2e3d commit 9e0baf6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/stores/data/watching.store.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { TraktCheckinRequest, TraktWatching } from '@dvcol/trakt-http-clien
66

77
import { NotificationService } from '~/services/notification.service';
88
import { TraktService } from '~/services/trakt.service';
9+
import { useAuthSettingsStoreRefs } from '~/stores/settings/auth.store';
910
import { logger } from '~/stores/settings/log.store';
1011
import { useUserSettingsStoreRefs } from '~/stores/settings/user.store';
1112
import { storage } from '~/utils/browser/browser-storage.utils';
@@ -149,16 +150,20 @@ export const useWatchingStore = defineStore(WatchingStoreConstants.Store, () =>
149150
}
150151
};
151152

153+
const { isAuthenticated } = useAuthSettingsStoreRefs();
152154
const interval = ref<ReturnType<typeof setInterval>>();
153155
const initWatchingStore = async () => {
154156
await restoreState();
155-
await fetchWatching();
156157
watch(
157158
polling,
158-
() => {
159+
async () => {
159160
if (interval.value) clearInterval(interval.value);
160161
if (!polling.value) return;
161-
interval.value = setInterval(() => fetchWatching(), polling.value);
162+
if (isAuthenticated.value) await fetchWatching();
163+
interval.value = setInterval(() => {
164+
if (!isAuthenticated.value) return;
165+
return fetchWatching();
166+
}, polling.value);
162167
logger.debug('Polling interval set to', polling.value);
163168
},
164169
{

0 commit comments

Comments
 (0)