Skip gql subscriptions until auth is properly set up

This commit is contained in:
schroda
2025-11-06 21:38:00 +01:00
parent 8ac93ff3ff
commit b062871163
2 changed files with 20 additions and 9 deletions

View File

@@ -124,7 +124,9 @@ const InitialBackgroundRequests = () => {
* and thus, data of existing chapters/mangas in the cache get outdated * and thus, data of existing chapters/mangas in the cache get outdated
*/ */
const BackgroundSubscriptions = () => { const BackgroundSubscriptions = () => {
const skipConnection = !AuthManager.useIsAuthenticated(); const { isAuthRequired, accessToken } = AuthManager.useSession();
const skipConnection = isAuthRequired === null || (isAuthRequired && !accessToken);
requestManager.useDownloadSubscription({ skip: skipConnection }); requestManager.useDownloadSubscription({ skip: skipConnection });
requestManager.useUpdaterSubscription({ skip: skipConnection }); requestManager.useUpdaterSubscription({ skip: skipConnection });

View File

@@ -6,7 +6,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
import { useSyncExternalStore } from 'react'; import { useMemo, useSyncExternalStore } from 'react';
import { AppStorage } from '@/lib/storage/AppStorage.ts'; import { AppStorage } from '@/lib/storage/AppStorage.ts';
let notifierValue = 0; let notifierValue = 0;
@@ -52,13 +52,22 @@ export class AuthManager {
} { } {
useSyncExternalStore(AuthManager.subscribe.bind(AuthManager), () => notifierValue); useSyncExternalStore(AuthManager.subscribe.bind(AuthManager), () => notifierValue);
return { return useMemo(
accessToken: AuthManager.accessToken, () => ({
refreshToken: AuthManager.getRefreshToken(), accessToken: AuthManager.accessToken,
isAuthRequired: AuthManager.authRequired, refreshToken: AuthManager.getRefreshToken(),
isInitialized: AuthManager.authInitialized, isAuthRequired: AuthManager.authRequired,
isRefreshingToken: AuthManager.refreshingToken, isInitialized: AuthManager.authInitialized,
}; isRefreshingToken: AuthManager.refreshingToken,
}),
[
AuthManager.accessToken,
AuthManager.getRefreshToken(),
AuthManager.authRequired,
AuthManager.authInitialized,
AuthManager.refreshingToken,
],
);
} }
static useIsAuthenticated(): boolean { static useIsAuthenticated(): boolean {