Berry-G / YoungCultureCenter

TEAM Young'tve jobs HOMEPAGE making project
0 stars 2 forks source link

로그인 세션 : 로그아웃 상태에서도 자동 로그아웃 기능 동작 이슈 #111

Closed Berry-G closed 1 year ago

Berry-G commented 1 year ago

문제 상황

Image

로그인이 되어있지 않아 로그인 버튼이 노출되는 상황에서도 개발자 모드로 코드를 열어보면 타이머가 작동하고 있다. 실제로도 타이머가 만료되면 로그인을 하지 않은 상황임에도 불구하고 로그아웃 페이지로 메소드가 전송된다.

해결방안

Berry-G commented 1 year ago

로그인 여부 체크하는 변수 수정

<c:set var="islogin" value="${sessionScope.id != null}" />

이용해서 분기 처리

<c:choose>
    <c:when test="${ islogin == true }">
        <!-- 로그인 세션이 있을 시 출력되는 부분 -->
        <div class="navbar-nav d-flex" style="justify-content: center; flex-wrap: nowrap;">
            <script type="text/javascript" charset="utf-8" src="/ycc/resources/js/timeoutchk.js"></script>
            <button class="btn btn-outline-success btn-sm me-2 hover-timer" style="white-space: nowrap;"
                onclick="javascript:refreshTimer()"><span id="timer"></span>
                <p class="mb-0"></p>
            </button>
            <div class="dropdown">
                <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown"
                    aria-expanded="false">
                    ${sessionScope.name} 님!</button>
                <ul class="dropdown-menu dropdown-menu-lg-end">
                    <li><button class="dropdown-item" type="button"
                            onclick="location.href='/ycc/mypage/pwcheck'">마이페이지</button></li>
                    <li><button class="dropdown-item" type="button" onclick="location.href='/ycc/mypage/mycourse'">나의
                            수강목록</button></li>
                    <li><button class="dropdown-item" type="button" onclick="location.href='/ycc/mypage/inquiry'">나의
                            문의내역</button></li>

                    <!-- 관리자 일떄 접근 가능한 관리자 페이지 버튼 -->
                    <c:if test="${sessionScope.grade=='관리자'}">
                        <li>
                            <hr class="dropdown-divider">
                        </li>
                        <li><button class="dropdown-item" type="button" onclick="location.href='/ycc/admin'">관리자
                                페이지</button></li>
                    </c:if>
                    <li>
                        <hr class="dropdown-divider">
                    </li>
                    <li><button class="dropdown-item dropdown-item-danger" type="button"
                            onclick="location.href='/ycc/logout'">로그아웃</button></li>
                </ul>
            </div>
        </div>
    </c:when>
    <c:when test="${ islogin == false }">
        <!-- 로그인 세션이 없을 떄 출력되는 부분 -->
        <div class="nav p-2 d-flex" style="justify-content: center; flex-wrap: nowrap;">
            <a class="btn btn-primary mx-2 text-nowrap" href="/ycc/login">로그인</a>
            <a class="btn btn-outline-primary text-nowrap" href="/ycc/signin/agree">회원가입</a>
        </div>
    </c:when>
</c:choose>

결과

Image

Image

Berry-G commented 1 year ago

커밋 완료