Fix UI :- Fix saved URL direct after login (#7799)

* Fix saved url direct after login

* allow overriding store redirect path
This commit is contained in:
Ashish Gupta 2022-09-30 17:21:52 +05:30 committed by GitHub
parent cc94b58168
commit 986ce4a8b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 12 deletions

View File

@ -139,16 +139,10 @@ export const AuthProvider = ({
* Stores redirect URL for successful login
*/
function storeRedirectPath() {
const redirectPathExists = Boolean(
cookieStorage.getItem(REDIRECT_PATHNAME)
);
if (!redirectPathExists) {
cookieStorage.setItem(REDIRECT_PATHNAME, appState.getUrlPathname(), {
expires: getUrlPathnameExpiry(),
path: '/',
});
}
cookieStorage.setItem(REDIRECT_PATHNAME, appState.getUrlPathname(), {
expires: getUrlPathnameExpiry(),
path: '/',
});
}
const resetUserDetails = (forceLogout = false) => {

View File

@ -31,7 +31,10 @@ import {
getResourcePermission,
} from '../../axiosAPIs/permissionAPI';
import { REDIRECT_PATHNAME } from '../../constants/constants';
import { isProtectedRoute } from '../../utils/AuthProvider.util';
import {
getUrlPathnameExpiryAfterRoute,
isProtectedRoute,
} from '../../utils/AuthProvider.util';
import {
getOperationPermissions,
getUIPermission,
@ -84,7 +87,10 @@ const PermissionProvider: FC<PermissionProviderProps> = ({ children }) => {
const redirectToStoredPath = () => {
const urlPathname = cookieStorage.getItem(REDIRECT_PATHNAME);
if (urlPathname) {
cookieStorage.removeItem(REDIRECT_PATHNAME);
cookieStorage.setItem(REDIRECT_PATHNAME, urlPathname, {
expires: getUrlPathnameExpiryAfterRoute(),
path: '/',
});
history.push(urlPathname);
}
};

View File

@ -232,6 +232,10 @@ export const getUrlPathnameExpiry = () => {
return new Date(Date.now() + 60 * 60 * 1000);
};
export const getUrlPathnameExpiryAfterRoute = () => {
return new Date(Date.now() + 1000);
};
/**
* @exp expiry of token
* @isExpired wether token is already expired or not