From ddbbf8df4b270f6a9209c4e9c2b9bf50f95b1794 Mon Sep 17 00:00:00 2001 From: Misi Date: Wed, 2 Oct 2024 12:08:25 +0200 Subject: [PATCH] Auth: Fix redirection in case of ERR_TOKEN_REVOKED (#94137) Fix redirection in case of token revoked error --- public/app/core/services/backend_srv.ts | 1 + public/app/core/services/context_srv.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index 64ac099efba..72be4f2ff4d 100644 --- a/public/app/core/services/backend_srv.ts +++ b/public/app/core/services/backend_srv.ts @@ -382,6 +382,7 @@ export class BackendSrv implements BackendService { }, }) ); + this.dependencies.contextSrv.setRedirectToUrl(); return throwError(() => error); } diff --git a/public/app/core/services/context_srv.ts b/public/app/core/services/context_srv.ts index 54e5c27594b..8d14b656fa2 100644 --- a/public/app/core/services/context_srv.ts +++ b/public/app/core/services/context_srv.ts @@ -120,16 +120,20 @@ export class ContextSrv { * Indicate the user has been logged out */ setLoggedOut() { + this.setRedirectToUrl(); + this.cancelTokenRotationJob(); + this.user.isSignedIn = false; + this.isSignedIn = false; + window.location.reload(); + } + + setRedirectToUrl() { if (config.featureToggles.useSessionStorageForRedirection) { window.sessionStorage.setItem( RedirectToUrlKey, encodeURIComponent(window.location.href.substring(window.location.origin.length)) ); } - this.cancelTokenRotationJob(); - this.user.isSignedIn = false; - this.isSignedIn = false; - window.location.reload(); } hasRole(role: string) {