mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
dbeaver/pro#6565 fix: prevent requests on session expire (#3678)
Co-authored-by: Evgenia <139753579+EvgeniaBzzz@users.noreply.github.com>
This commit is contained in:
co-authored by
Evgenia
parent
a0944850b1
commit
c8c82c7f3e
@@ -11,6 +11,8 @@ import { type ILoadableState, isContainsException } from '@cloudbeaver/core-util
|
||||
|
||||
import { getComputed } from '../getComputed.js';
|
||||
import { useObjectRef } from '../useObjectRef.js';
|
||||
import { useService } from '@cloudbeaver/core-di';
|
||||
import { SessionExpireService } from '@cloudbeaver/core-root';
|
||||
|
||||
export function useAutoLoad(
|
||||
component: { name: string },
|
||||
@@ -18,7 +20,8 @@ export function useAutoLoad(
|
||||
enabled = true,
|
||||
lazy = false,
|
||||
throwExceptions = false,
|
||||
) {
|
||||
): void {
|
||||
const sessionExpireService = useService(SessionExpireService);
|
||||
const unmountedRef = useObjectRef({ unmounted: false });
|
||||
const [loadFunctionName] = useState(`${component.name}.useAutoLoad(...)` as const);
|
||||
if (!Array.isArray(state)) {
|
||||
@@ -34,7 +37,7 @@ export function useAutoLoad(
|
||||
|
||||
const obj = {
|
||||
[loadFunctionName]: async () => {
|
||||
if (!enabled || unmountedRef.unmounted) {
|
||||
if (!enabled || unmountedRef.unmounted || sessionExpireService.expired) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
} from '@cloudbeaver/core-resource';
|
||||
import { type ILoadableState, isContainsException, LoadingError } from '@cloudbeaver/core-utils';
|
||||
import { mutex } from '@dbeaver/js-helpers';
|
||||
import { SessionExpireService } from '@cloudbeaver/core-root';
|
||||
|
||||
import { ErrorContext } from '../ErrorContext.js';
|
||||
import { useObjectRef } from '../useObjectRef.js';
|
||||
@@ -112,6 +113,7 @@ export function useResource<
|
||||
): IMapResourceResult<TResource, TIncludes> | IMapResourceListResult<TResource, TIncludes> | IDataResourceResult<TResource, TIncludes> {
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
const resource = ctor instanceof Resource ? ctor : useService(ctor);
|
||||
const sessionExpireService = useService(SessionExpireService);
|
||||
const unmountedRef = useObjectRef({ unmounted: false });
|
||||
const errorContext = useContext(ErrorContext);
|
||||
const [loadingException, setLoadingException] = useState<Error | null>(null);
|
||||
@@ -201,7 +203,7 @@ export function useResource<
|
||||
const loading = getComputed(() => key !== null && resource.isLoading(key));
|
||||
const loaded = getComputed(() => key === null || resource.isLoaded(key, includes));
|
||||
const outdated = getComputed(() => key === null || resource.isOutdated(key, includes));
|
||||
const canLoad = key !== null && actions?.freeze !== true && preloaded && outdated && !loading;
|
||||
const canLoad = key !== null && actions?.freeze !== true && preloaded && outdated && !loading && !sessionExpireService.expired;
|
||||
|
||||
const result = useMemo<IMapResourceResult<TResource, TIncludes> | IMapResourceListResult<TResource, TIncludes>>(
|
||||
() => ({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* CloudBeaver - Cloud Database Manager
|
||||
* Copyright (C) 2020-2024 DBeaver Corp and others
|
||||
* Copyright (C) 2020-2025 DBeaver Corp and others
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0.
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -9,6 +9,7 @@ import { Bootstrap, injectable } from '@cloudbeaver/core-di';
|
||||
import { Executor, type IExecutor } from '@cloudbeaver/core-executor';
|
||||
import { EServerErrorCode, GQLError, GraphQLService, SessionError } from '@cloudbeaver/core-sdk';
|
||||
import { errorOf } from '@cloudbeaver/core-utils';
|
||||
import { makeObservable, observable } from 'mobx';
|
||||
|
||||
export const SESSION_EXPIRE_MIN_TIME = 5 * 1000 * 60;
|
||||
|
||||
@@ -23,9 +24,12 @@ export class SessionExpireService extends Bootstrap {
|
||||
this.sessionExpired = this.sessionExpired.bind(this);
|
||||
|
||||
this.onSessionExpire = new Executor();
|
||||
makeObservable<this, 'isExpired'>(this, {
|
||||
isExpired: observable,
|
||||
});
|
||||
}
|
||||
|
||||
get expired() {
|
||||
get expired(): boolean {
|
||||
return this.isExpired;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user