Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/app/components/BurgerMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import IconGlobe from "../../assets/icon-globe.svg";
import IconSat from "../../assets/icon-satellite.svg";
import IconUser from "../../assets/icon-user.svg";
import IconQuestion from "../../assets/icon-question.svg";
import { logout } from "../../auth/auth-helpers";

export default function BurgerMenu() {
const [menuOpen, setMenuOpen] = useState(false);
Expand All @@ -19,6 +20,12 @@ export default function BurgerMenu() {
const closeMenu = () => {
setMenuOpen(false);
};

const logoutAndClose = () => {
closeMenu();
logout();
};

return (
<Menu
isOpen={menuOpen}
Expand All @@ -40,6 +47,12 @@ export default function BurgerMenu() {
LOG IN
</NavLink>
) : null}

{userAddress !== "none" ? (
<NavLink onClick={() => logoutAndClose()} to={"/"}>
LOG OUT
</NavLink>
) : null}
<br></br>

<NavLink onClick={() => closeMenu()} to={"/"}>
Expand Down
9 changes: 9 additions & 0 deletions src/auth/auth-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,12 @@ export const decryptSecret = (secret, password) => {
}
return privateKey;
};

export const logout = history => {
localStorage.removeItem("trusat-login-credentials");
localStorage.removeItem("trusat-allow-cookies");
if (history) {
history.push("/");
}
window.location.reload();
};
11 changes: 3 additions & 8 deletions src/views/AccountSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import DataSettings from "../user/components/DataSettings";
import SecuritySettings from "../user/components/SecuritySettings";
import Spinner from "../app/components/Spinner";
import Button from "../app/components/Button";
import { checkAuthExpiry } from "../auth/auth-helpers";
import { checkAuthExpiry, logout } from "../auth/auth-helpers";

function UserSettings({ history }) {
const profileDispatch = useProfileDispatch();
Expand Down Expand Up @@ -108,12 +108,7 @@ function UserSettings({ history }) {
}
};

const logout = () => {
localStorage.removeItem("trusat-login-credentials");
localStorage.removeItem("trusat-allow-cookies");
history.push("/");
window.location.reload();
};
const logoutAndClose = history => logout(history);

return fetchProfileErrorMessage ? (
<p className="app__error-message">
Expand Down Expand Up @@ -172,7 +167,7 @@ function UserSettings({ history }) {
color="white"
text="logout"
addStyles="account-settings__log-out-button"
onClick={logout}
onClick={logoutAndClose}
></Button>
</div>
);
Expand Down