Skip to content

Commit

Permalink
Clear the plan and recipe cache on signout
Browse files Browse the repository at this point in the history
  • Loading branch information
alex9smith committed Nov 27, 2024
1 parent 63cda87 commit 477d0cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions frontend/src/components/TopNav/TopNav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HomeIcon } from "@primer/octicons-react";
import { useNavigate } from "react-router";
import { googleLogout } from "@react-oauth/google";
import { authenticationService } from "../../services/authentication";
import { apiClient } from "../../services/apiClient";
import { isProduction } from "../../constants";

function TopNav() {
Expand All @@ -13,6 +14,7 @@ function TopNav() {
as="div"
onClick={() => {
authenticationService.logout();
apiClient.clearCache();
if (isProduction()) {
googleLogout();
}
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/services/apiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ class ApiClient {
cachedRecipes.recipes = cachedRecipes.filter((recipe) => recipe.id !== id);
this.#cacheItem("recipes", cachedRecipes);
}

clearCache() {
this.storage.removeItem("plan");
this.storage.removeItem("recipes");
}
}

export const apiClient = new ApiClient(getApiBaseUrl());

0 comments on commit 477d0cb

Please sign in to comment.