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:
17
src/App.tsx
17
src/App.tsx
@@ -103,20 +103,13 @@ const ScrollToTop = () => {
|
||||
};
|
||||
|
||||
const InitialBackgroundRequests = () => {
|
||||
const { isAuthRequired, accessToken } = AuthManager.useSession();
|
||||
const skipConnection = isAuthRequired == null || (!isAuthRequired && !accessToken);
|
||||
|
||||
const [fetchExtensionList] = requestManager.useExtensionListFetch();
|
||||
|
||||
useEffect(() => {
|
||||
if (skipConnection) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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.
|
||||
fetchExtensionList().catch(defaultPromiseErrorHandler('App::InitialBackgroundRequests: extension list'));
|
||||
}, [skipConnection]);
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
};
|
||||
@@ -128,10 +121,7 @@ const InitialBackgroundRequests = () => {
|
||||
* and thus, data of existing chapters/mangas in the cache get outdated
|
||||
*/
|
||||
const BackgroundSubscriptions = () => {
|
||||
// Listen to session changes
|
||||
const { isAuthRequired, accessToken } = AuthManager.useSession();
|
||||
|
||||
const skipConnection = isAuthRequired == null || (!isAuthRequired && !accessToken);
|
||||
const skipConnection = !AuthManager.useIsAuthenticated();
|
||||
|
||||
// Load the full download status once on startup to fill the cache
|
||||
requestManager.useGetDownloadStatus({ nextFetchPolicy: 'standby' });
|
||||
@@ -153,9 +143,8 @@ const ReactRouterSetter = () => {
|
||||
};
|
||||
|
||||
const PrivateRoutes = () => {
|
||||
const { isAuthRequired, accessToken, refreshToken } = AuthManager.useSession();
|
||||
const isAuthenticated = AuthManager.useIsAuthenticated();
|
||||
|
||||
const isAuthenticated = !isAuthRequired || (isAuthRequired && (accessToken || refreshToken));
|
||||
if (!isAuthenticated) {
|
||||
return (
|
||||
<Navigate
|
||||
|
||||
@@ -61,6 +61,12 @@ export class AuthManager {
|
||||
};
|
||||
}
|
||||
|
||||
static useIsAuthenticated(): boolean {
|
||||
const { isAuthRequired, accessToken, refreshToken } = AuthManager.useSession();
|
||||
|
||||
return !isAuthRequired || (isAuthRequired && (!!accessToken || !!refreshToken));
|
||||
}
|
||||
|
||||
static isAuthInitialized(): boolean {
|
||||
return AuthManager.authInitialized;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ export const LoginPage = () => {
|
||||
const { t } = useTranslation();
|
||||
const { setOverride } = useNavBarContext();
|
||||
const navigate = useNavigate();
|
||||
const { isAuthRequired, accessToken, refreshToken } = AuthManager.useSession();
|
||||
const isAuthenticated = AuthManager.useIsAuthenticated();
|
||||
|
||||
const [redirect] = useQueryParam(SearchParam.REDIRECT, StringParam);
|
||||
const [loginUser, { loading: isLoading }] = requestManager.useLoginUser();
|
||||
@@ -38,8 +38,6 @@ export const LoginPage = () => {
|
||||
const [username, setUsername] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
|
||||
const isAuthenticated = !isAuthRequired || (isAuthRequired && !!accessToken && !!refreshToken);
|
||||
|
||||
const doLogin = async () => {
|
||||
try {
|
||||
const { data } = await loginUser({ variables: { username, password } });
|
||||
|
||||
Reference in New Issue
Block a user