Skip to content

Commit

Permalink
Clear persisted data on user logout
Browse files Browse the repository at this point in the history
Make sure that the persisted redux states are cleared before logging
out.
  • Loading branch information
spaceo committed Aug 17, 2024
1 parent 4f7864f commit b9d07e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/apps/menu/menu-logged-in/MenuLoggedInContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import DashboardNotificationList from "../../dashboard/dashboard-notification-li
import useReservations from "../../../core/utils/useReservations";
import useLoans from "../../../core/utils/useLoans";
import { usePatronData } from "../../../core/utils/helpers/usePatronData";
import { resetPersistedData } from "../../../core/store";

interface MenuLoggedInContentProps {
pageSize: number;
Expand Down Expand Up @@ -111,6 +112,7 @@ const MenuLoggedInContent: FC<MenuLoggedInContentProps> = ({ pageSize }) => {
<div className="modal-profile__btn-logout mx-32">
<Link
className="btn-primary btn-filled btn-large arrow__hover--right-small"
onClick={() => resetPersistedData()}
href={logoutUrl}
>
{t("menuLogOutText")}
Expand Down
12 changes: 11 additions & 1 deletion src/components/atoms/links/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getLinkHandler } from "./getLinkHandler";

export interface LinkProps {
href: URL;
onClick?: () => Promise<void>;
children: React.ReactNode;
isNewTab?: boolean;
className?: string;
Expand All @@ -16,6 +17,7 @@ export interface LinkProps {

const Link: React.FC<LinkProps> = ({
href,
onClick,
children,
isNewTab = false,
className,
Expand All @@ -42,6 +44,14 @@ const Link: React.FC<LinkProps> = ({
trackClick
});

const onclickHandler = onClick
? (
e:
| React.MouseEvent<HTMLAnchorElement>
| React.KeyboardEvent<HTMLAnchorElement>
) => onClick().then(() => handleClick(e))
: handleClick;

return (
<a
id={id}
Expand All @@ -50,7 +60,7 @@ const Link: React.FC<LinkProps> = ({
target={isNewTab ? "_blank" : undefined}
rel="noreferrer"
className={className}
onClick={handleClick}
onClick={onclickHandler}
onKeyUp={handleKeyUp}
aria-labelledby={ariaLabelledBy}
tabIndex={isHiddenFromScreenReaders ? -1 : 0}
Expand Down
2 changes: 2 additions & 0 deletions src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;
export type TypedDispatch = ThunkDispatch<RootState, never, never>;
export const useSelector: TypedUseSelectorHook<RootState> = rawUseSelector;

export const resetPersistedData = async () => persistor.purge();

0 comments on commit b9d07e3

Please sign in to comment.