Skip to content

Commit

Permalink
fix(client): multi-node get/set logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Jan 18, 2024
1 parent 07810ce commit fe879ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions client/src/components/pages/ProtectedPageContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const ProtectedPageContainer = React.memo(({children}) => {

useEffect(() => {
if (node && isLoaded && userData) {
setHasLoggedIn();
setHasLoggedIn(node);
} else if (node && isLoaded && !userData) {
if (getHasLoggedIn()) {
if (getHasLoggedIn(node)) {
triggerLogIn();
}
}
Expand Down
13 changes: 7 additions & 6 deletions client/src/helpers/localStorage.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const LS_HAS_LOGGED_IN_BEFORE = 'EPIVAR_HAS_LOGGED_IN_BEFORE';
const LS_HAS_LOGGED_IN_BEFORE = "EPIVAR_HAS_LOGGED_IN_BEFORE";

export const setHasLoggedIn = () => {
localStorage.setItem(LS_HAS_LOGGED_IN_BEFORE, "1");
}
const getLoggedInObject = () => JSON.parse(localStorage.getItem(LS_HAS_LOGGED_IN_BEFORE) || "{}");

export const getHasLoggedIn = () => {
return localStorage.getItem(LS_HAS_LOGGED_IN_BEFORE) === "1";
export const setHasLoggedIn = (node) => {
const existing = getLoggedInObject();
localStorage.setItem(LS_HAS_LOGGED_IN_BEFORE, JSON.stringify({...existing, [node]: true}));
}

export const getHasLoggedIn = (node) => (getLoggedInObject()[node]) ?? false;

0 comments on commit fe879ee

Please sign in to comment.