diff --git a/src/services/mal/MalAuth.ts b/src/services/mal/MalAuth.ts index e4f7f5e5..73e86537 100644 --- a/src/services/mal/MalAuth.ts +++ b/src/services/mal/MalAuth.ts @@ -47,6 +47,10 @@ class MalAuthService { return this.token; } + isAuthenticated(): boolean { + return this.getToken() !== null; + } + saveToken(token: MalToken) { this.token = token; mmkvStorage.setString(KEYS.ACCESS, token.accessToken); diff --git a/src/services/mal/MalSync.ts b/src/services/mal/MalSync.ts index 09f1d04b..f93fa35b 100644 --- a/src/services/mal/MalSync.ts +++ b/src/services/mal/MalSync.ts @@ -188,7 +188,7 @@ export const MalSync = { const isEnabled = mmkvStorage.getBoolean('mal_enabled') ?? true; const isAutoUpdate = mmkvStorage.getBoolean('mal_auto_update') ?? true; - if (!isEnabled || !isAutoUpdate) { + if (!isEnabled || !isAutoUpdate || !MalAuth.isAuthenticated()) { return; } @@ -286,10 +286,10 @@ export const MalSync = { */ scrobbleDirect: async (malId: number, episodeNumber: number) => { try { - // Respect user settings + // Respect user settings and login status const isEnabled = mmkvStorage.getBoolean('mal_enabled') ?? true; const isAutoUpdate = mmkvStorage.getBoolean('mal_auto_update') ?? true; - if (!isEnabled || !isAutoUpdate) return; + if (!isEnabled || !isAutoUpdate || !MalAuth.isAuthenticated()) return; // Check current status const currentInfo = await MalApiService.getMyListStatus(malId); @@ -325,6 +325,7 @@ export const MalSync = { * Import MAL list items into local library */ syncMalToLibrary: async () => { + if (!MalAuth.isAuthenticated()) return false; try { let allItems: MalAnimeNode[] = []; let offset = 0; @@ -366,6 +367,7 @@ export const MalSync = { * Automatically adds MAL 'watching' items to the Nuvio Library */ syncMalWatchingToLibrary: async () => { + if (!MalAuth.isAuthenticated()) return; try { logger.log('[MalSync] Auto-syncing MAL watching items to library...'); diff --git a/src/services/watchedService.ts b/src/services/watchedService.ts index a923bf7f..e83e0bf5 100644 --- a/src/services/watchedService.ts +++ b/src/services/watchedService.ts @@ -219,10 +219,9 @@ class WatchedService { } // Sync to MAL - const malToken = MalAuth.getToken(); - if (malToken) { + if (MalAuth.isAuthenticated()) { MalSync.scrobbleEpisode( - title || '', // Use real title if provided for search fallback + title || 'Movie', // Use real title or generic fallback 1, 1, 'movie', @@ -300,8 +299,7 @@ class WatchedService { } // Sync to MAL - const malToken = MalAuth.getToken(); - if (malToken && (showImdbId || malId || tmdbId)) { + if (MalAuth.isAuthenticated() && (showImdbId || malId || tmdbId)) { // Strategy 0: Direct Match (if malId is provided) let synced = false; if (malId) {