로그아웃 기능이 동작하면 세션이 삭제되고 로그인 페이지로 되돌아가게 됩니다.
하지만 사용자는 단순히 로그인 화면으로 돌아온 것만으로는
"로그아웃이 잘 된 건지" 명확히 알 수 없습니다.
서버에서 로그아웃 시 /member/login?msg=logout 형태로 쿼리스트링 값을 함께 전달합니다.
이 값을 EJS 템플릿에서 감지해 "로그아웃이 완료되었습니다."라는 메시지를 출력하도록 합니다.
▼ Code
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>로그인</title>
<link rel="stylesheet" href="/static/common.css" />
</head>
<body>
<h2>로그인</h2>
<form method="post">
<input name="userid" placeholder="아이디" required />
<br />
<input name="pwd" type="password" placeholder="비밀번호" required />
<br />
<button type="submit">로그인</button>
</form>
<% if (typeof msg !== 'undefined' && msg === 'fail') { %>
<p style="color: red">로그인에 실패했습니다.</p>
<% } else if (typeof msg !== 'undefined' && msg === 'logout') { %>
<p style="color: red">로그아웃이 완료되었습니다.</p>
<% } %>
</body>
</html>
▼ Explain
else if msg=logout일 때 실행되는 분기입니다. typeof msg !== 'undefined' msg 변수가 정의되어 있는지 확인합니다. URL에 msg 값이 없을 경우 오류를 방지하기 위한 안전한 검사입니다. msg === 'logout' msg 값이 'logout'인 경우, 즉 로그아웃 후 리다이렉트된 상태임을 의미합니다. 로그인 페이지로 돌아올 때 서버(MemberService.js)에서 res.redirect('/member/login?msg=logout'); 구문으로 전달됩니다. <p style="color: red">로그아웃이 완료되었습니다.</p> 로그아웃 성공 안내 문구를 표시합니다. 사용자가 로그아웃 동작이 정상적으로 수행되었음을 한눈에 확인할 수 있습니다.
개인정보처리방침 · 이용약관