mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2026-01-08 05:26:19 +00:00
fix(ui): validate token expiry on tab focus (#10011)
* fix(ui): validate token expiry on tab focus * show toast message if token is expired
This commit is contained in:
parent
10b15e782e
commit
d464a8a255
@ -19,7 +19,9 @@ import { observer } from 'mobx-react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Link, useHistory, useLocation, useRouteMatch } from 'react-router-dom';
|
||||
import { toast } from 'react-toastify';
|
||||
import { getVersion } from 'rest/miscAPI';
|
||||
import { extractDetailsFromToken } from 'utils/AuthProvider.util';
|
||||
import appState from '../../AppState';
|
||||
import {
|
||||
getExplorePathWithSearch,
|
||||
@ -336,6 +338,28 @@ const Appbar: React.FC = (): JSX.Element => {
|
||||
}
|
||||
}, [appState.userDetails, isAuthDisabled]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleDocumentVisibilityChange = () => {
|
||||
if (
|
||||
isProtectedRoute(location.pathname) &&
|
||||
isTourRoute(location.pathname)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const { isExpired, exp } = extractDetailsFromToken();
|
||||
if (!document.hidden && isExpired) {
|
||||
exp && toast.info(t('message.session-expired'));
|
||||
onLogoutHandler();
|
||||
}
|
||||
};
|
||||
|
||||
addEventListener('focus', handleDocumentVisibilityChange);
|
||||
|
||||
return () => {
|
||||
removeEventListener('focus', handleDocumentVisibilityChange);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
{isProtectedRoute(location.pathname) &&
|
||||
|
||||
@ -788,6 +788,7 @@
|
||||
"select-team": "Please select a team type",
|
||||
"select-token-expiration": "Select Token Expiration",
|
||||
"service-created-entity-description": "The <Service Name> has been created successfully. Visit the newly created service to take a look at the details. {{entity}}",
|
||||
"session-expired": "Your session has timed out! Please sign in again to access OpenMetadata.",
|
||||
"something-went-wrong": "Something went wrong",
|
||||
"special-character-not-allowed": "Special characters are not allowed.",
|
||||
"sql-query-tooltip": "Queries returning one or more rows will result in the test failing.",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user