Skip to content

refactor: 로그아웃 기능 수정 #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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: 12 additions & 1 deletion src/main/webapp/WEB-INF/views/include/header.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ prefix="fn" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
}
});
})

const onLogoutButtonClickHandler = () => {
$.ajax({
url: '/user/logout',
type: 'POST',
success: () => {
sessionStorage.setItem('logoutMessage', '정상적으로 로그아웃 되었습니다.');
window.location.href = '/sign-in';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

화면 이동해도 데이터를 쓰기 위해서 sessionStorage를 사용하는 군요!!

원래 sessionStorage를 이렇게 사용하나용 (텍스트라 그렇지 궁금해서 물어보는겁니다)

이게 뭔가 key를 한쪽에서 관리하지 않으면 나중에 문제가 생길 수 있을 것 같은 기분이 들긴합니다.

},
});
}
</script>

<header class="header">
Expand All @@ -55,7 +66,7 @@ prefix="fn" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<div id="user-box" class="header-user-info-box" style="display: none;">
<div class="header-user-info-mypage-button">마이페이지</div>
<div class="divider"></div>
<div class="header-user-info-logout-button">로그아웃</div>
<div class="header-user-info-logout-button" onclick="onLogoutButtonClickHandler()">로그아웃</div>
</div>
</c:if>
</ul>
Expand Down
20 changes: 14 additions & 6 deletions src/main/webapp/WEB-INF/views/user/sign-in.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ prefix="fn" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<meta charset="UTF-8" />
<title>가계부</title>
<!-- CSS -->
<link href="../css/include/global.css?ver=1" rel="stylesheet" />
<link href="../css/user.css?ver=1" rel="stylesheet" />
<link href="/css/include/global.css?ver=1" rel="stylesheet" />
<link href="/css/user.css?ver=1" rel="stylesheet" />
<!-- JQuery 최신 -->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<!-- Sweet Alert -->
Expand Down Expand Up @@ -42,15 +42,13 @@ $(document).ready(() => {
password: password,
}),
contentType: "application/json; charset=utf-8",
dataType: "text",
success: (data) => {
if (data) {
dataType: "json",
success: (response) => {
sessionStorage.setItem(
"successMessage",
"님 환영합니다!"
);
window.location.href = "/user/mypage";
}
},
error: (error) => {
if (error.status === 400) {
Expand Down Expand Up @@ -152,5 +150,15 @@ $(document).ready(() => {
});
sessionStorage.removeItem('successMessage');
}
});
$(document).ready(() => {
const logoutMessage = sessionStorage.getItem('logoutMessage');
if (logoutMessage) {
Toast.fire({
icon: 'success',
title: logoutMessage,
});
sessionStorage.removeItem('logoutMessage');
}
});
</script>