Simplify session context usage

Most cases were preventing some requests from getting triggered. However, this is not necessary anymore since with 6636cc66b1, this is handled globally now
This commit is contained in:
schroda
2025-10-16 21:52:50 +02:00
parent 258d1a496a
commit 18deca32f6
3 changed files with 10 additions and 17 deletions

View File

@@ -103,20 +103,13 @@ const ScrollToTop = () => {
}; };
const InitialBackgroundRequests = () => { const InitialBackgroundRequests = () => {
const { isAuthRequired, accessToken } = AuthManager.useSession();
const skipConnection = isAuthRequired == null || (!isAuthRequired && !accessToken);
const [fetchExtensionList] = requestManager.useExtensionListFetch(); const [fetchExtensionList] = requestManager.useExtensionListFetch();
useEffect(() => { useEffect(() => {
if (skipConnection) {
return;
}
// Fetch extension list on startup to show up-to-date number of available extension updates in the navigation bar // Fetch extension list on startup to show up-to-date number of available extension updates in the navigation bar
// without having to open the extensions page. // without having to open the extensions page.
fetchExtensionList().catch(defaultPromiseErrorHandler('App::InitialBackgroundRequests: extension list')); fetchExtensionList().catch(defaultPromiseErrorHandler('App::InitialBackgroundRequests: extension list'));
}, [skipConnection]); }, []);
return null; return null;
}; };
@@ -128,10 +121,7 @@ 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 = () => {
// Listen to session changes const skipConnection = !AuthManager.useIsAuthenticated();
const { isAuthRequired, accessToken } = AuthManager.useSession();
const skipConnection = isAuthRequired == null || (!isAuthRequired && !accessToken);
// Load the full download status once on startup to fill the cache // Load the full download status once on startup to fill the cache
requestManager.useGetDownloadStatus({ nextFetchPolicy: 'standby' }); requestManager.useGetDownloadStatus({ nextFetchPolicy: 'standby' });
@@ -153,9 +143,8 @@ const ReactRouterSetter = () => {
}; };
const PrivateRoutes = () => { const PrivateRoutes = () => {
const { isAuthRequired, accessToken, refreshToken } = AuthManager.useSession(); const isAuthenticated = AuthManager.useIsAuthenticated();
const isAuthenticated = !isAuthRequired || (isAuthRequired && (accessToken || refreshToken));
if (!isAuthenticated) { if (!isAuthenticated) {
return ( return (
<Navigate <Navigate

View File

@@ -61,6 +61,12 @@ export class AuthManager {
}; };
} }
static useIsAuthenticated(): boolean {
const { isAuthRequired, accessToken, refreshToken } = AuthManager.useSession();
return !isAuthRequired || (isAuthRequired && (!!accessToken || !!refreshToken));
}
static isAuthInitialized(): boolean { static isAuthInitialized(): boolean {
return AuthManager.authInitialized; return AuthManager.authInitialized;
} }

View File

@@ -30,7 +30,7 @@ export const LoginPage = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const { setOverride } = useNavBarContext(); const { setOverride } = useNavBarContext();
const navigate = useNavigate(); const navigate = useNavigate();
const { isAuthRequired, accessToken, refreshToken } = AuthManager.useSession(); const isAuthenticated = AuthManager.useIsAuthenticated();
const [redirect] = useQueryParam(SearchParam.REDIRECT, StringParam); const [redirect] = useQueryParam(SearchParam.REDIRECT, StringParam);
const [loginUser, { loading: isLoading }] = requestManager.useLoginUser(); const [loginUser, { loading: isLoading }] = requestManager.useLoginUser();
@@ -38,8 +38,6 @@ export const LoginPage = () => {
const [username, setUsername] = useState(''); const [username, setUsername] = useState('');
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
const isAuthenticated = !isAuthRequired || (isAuthRequired && !!accessToken && !!refreshToken);
const doLogin = async () => { const doLogin = async () => {
try { try {
const { data } = await loginUser({ variables: { username, password } }); const { data } = await loginUser({ variables: { username, password } });