diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index be9a2c01cbf..559fbff18ff 100644 --- a/public/app/core/services/backend_srv.ts +++ b/public/app/core/services/backend_srv.ts @@ -19,7 +19,7 @@ import { AppEvents, DataQueryErrorType } from '@grafana/data'; import { BackendSrv as BackendService, BackendSrvRequest, config, FetchError, FetchResponse } from '@grafana/runtime'; import appEvents from 'app/core/app_events'; import { getConfig } from 'app/core/config'; -import { getSessionExpiry } from 'app/core/utils/auth'; +import { getSessionExpiry, hasSessionExpiry } from 'app/core/utils/auth'; import { loadUrlToken } from 'app/core/utils/urlToken'; import { DashboardModel } from 'app/features/dashboard/state'; import { DashboardSearchItem } from 'app/features/search/types'; @@ -390,10 +390,11 @@ export class BackendSrv implements BackendService { } let authChecker = this.loginPing(); - - const expired = getSessionExpiry() * 1000 < Date.now(); - if (expired) { - authChecker = this.rotateToken(); + if (hasSessionExpiry()) { + const expired = getSessionExpiry() * 1000 < Date.now(); + if (expired) { + authChecker = this.rotateToken(); + } } return from(authChecker).pipe( diff --git a/public/app/core/specs/backend_srv.test.ts b/public/app/core/specs/backend_srv.test.ts index 54118ce553f..075ec6f0095 100644 --- a/public/app/core/specs/backend_srv.test.ts +++ b/public/app/core/specs/backend_srv.test.ts @@ -86,6 +86,11 @@ const getTestContext = (overides?: object, mockFromFetch = true) => { }; }; +jest.mock('app/core/utils/auth', () => ({ + getSessionExpiry: () => 1, + hasSessionExpiry: () => true, +})); + describe('backendSrv', () => { describe('parseRequestOptions', () => { it.each` diff --git a/public/app/core/utils/auth.ts b/public/app/core/utils/auth.ts index 42d99cd59c9..8c6b69cc028 100644 --- a/public/app/core/utils/auth.ts +++ b/public/app/core/utils/auth.ts @@ -11,3 +11,7 @@ export function getSessionExpiry() { return parseInt(expiresStr, 10); } + +export function hasSessionExpiry() { + return document.cookie.split('; ').findIndex((row) => row.startsWith('grafana_session_expiry=')) > -1; +}