Skip to content

Commit

Permalink
add function to remove current user from local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
daronenko committed Sep 29, 2024
1 parent ea3860e commit 4cb15e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/header/header.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { View } from "../../view.js";
import { Ajax } from "../../modules/ajax.js";
import { getCurrentUser } from "../../modules/user.js";
import { getCurrentUser, removeCurrentUser } from "../../modules/user.js";
import { API_URL } from "../../app/config.js";

export class HeaderView extends View {
Expand Down Expand Up @@ -92,7 +92,7 @@ export class HeaderView extends View {
const response = await Ajax.post(url);

if (response.status === 200) {
localStorage.removeItem("user");
removeCurrentUser();
this.router.renderLayout();
} else {
console.error("logout failed:", response.body);
Expand Down
7 changes: 7 additions & 0 deletions src/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ export const getCurrentUser = () => {
export const setCurrentUser = (user) => {
localStorage.setItem("user", JSON.stringify(user));
};

/**
* Removes current user from local storage
*/
export const removeCurrentUser = () => {
localStorage.removeItem("user");
};

0 comments on commit 4cb15e8

Please sign in to comment.