Merge pull request #10379 from jakemcdermott/fix-logout-reload2

Avoid reload on manual logout

SUMMARY
#10383
Instead of reloading, set the authRedirectTo context variable to "/logout" and handle it as a special case when routing

Reviewed-by: Marliana Lara <marliana.lara@gmail.com>
This commit is contained in:
softwarefactory-project-zuul[bot] 2021-06-08 13:58:14 +00:00 committed by GitHub
commit 6d433cc42a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -86,7 +86,7 @@ const AuthorizedRoutes = ({ routeConfig }) => {
};
const ProtectedRoute = ({ children, ...rest }) => {
const { setAuthRedirectTo } = useSession();
const { authRedirectTo, setAuthRedirectTo } = useSession();
const { pathname } = useLocation();
if (isAuthenticated(document.cookie)) {
@ -99,7 +99,8 @@ const ProtectedRoute = ({ children, ...rest }) => {
);
}
setAuthRedirectTo(pathname);
setAuthRedirectTo(authRedirectTo === '/logout' ? '/' : pathname);
return <Redirect to="/login" />;
};

View File

@ -74,14 +74,14 @@ function SessionProvider({ children }) {
const logout = useCallback(async () => {
if (!isSessionExpired.current) {
history.replace('/');
setAuthRedirectTo('/logout');
}
await RootAPI.logout();
setSessionTimeout(0);
setSessionCountdown(0);
clearTimeout(sessionTimeoutId.current);
clearInterval(sessionIntervalId.current);
}, [setSessionTimeout, setSessionCountdown, history]);
}, [setSessionTimeout, setSessionCountdown]);
useEffect(() => {
if (!isAuthenticated(document.cookie)) {