Skip to content

Commit

Permalink
fix: clear inactivity param when user logs in after inactivity (#594) (
Browse files Browse the repository at this point in the history
…#595)

* fix: clear inactivity param when user logs in after inactivity (#594)

* fix: updated inactivity timeout regex (#594)

---------

Co-authored-by: Fran McDade <[email protected]>
  • Loading branch information
frano-m and Fran McDade authored Apr 10, 2024
1 parent 4828886 commit 5494ac7
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Router, { useRouter } from "next/router";
import { useEffect, useMemo, useRef } from "react";
import { escapeRegExp } from "../../common/utils";
import { ROUTE_LOGIN } from "../../providers/authentication";
import { INACTIVITY_PARAM } from "../useSessionTimeout";
import { AUTHENTICATION_STATUS } from "./common/entities";

/**
Expand Down Expand Up @@ -34,7 +36,19 @@ export const useAuthenticationComplete = (
* @returns path to be used as the initial route history.
*/
function initRouteHistory(path: string): string {
return path === ROUTE_LOGIN ? "/" : path;
return path === ROUTE_LOGIN ? "/" : removeInactivityTimeoutQueryParam(path);
}

/**
* Removes the inactivity timeout query parameter from the path.
* the inactivity timeout parameter is used to indicate that the session has timed out; remove the parameter to
* clear the session timeout banner after the user logs in again.
* @param path - Path.
* @returns path without the inactivity timeout query parameter.
*/
function removeInactivityTimeoutQueryParam(path: string): string {
const regex = new RegExp(`\\?${escapeRegExp(INACTIVITY_PARAM)}(?:$|[=&].*)`);
return path.replace(regex, "");
}

/**
Expand All @@ -44,8 +58,9 @@ function initRouteHistory(path: string): string {
* @returns updated path to be used as the route history.
*/
function updateRouteHistory(prevPath: string, path: string): string {
let currentPath = prevPath;
if (path !== ROUTE_LOGIN) {
return path;
currentPath = path;
}
return prevPath;
return removeInactivityTimeoutQueryParam(currentPath);
}

0 comments on commit 5494ac7

Please sign in to comment.