Skip to content

Commit

Permalink
fix: logout 에러 수정 (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitchannn authored Mar 13, 2024
1 parent dc8bbd4 commit 8cee305
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void extendTime(final Long sessionId) {

@Transactional
public void logout(final Long memberId) {
final Session session = sessionRepository.getByMemberId(memberId);
final Session session = sessionRepository.getByMemberIdAndIsLoggedInTrue(memberId);
session.logout();
}
}
5 changes: 3 additions & 2 deletions server/src/main/java/sunflower/server/entity/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class Session {
private Long memberId;
private LocalDateTime createdAt;
private LocalDateTime expiredAt;
private Boolean isLoggedIn = Boolean.TRUE;
private Boolean deleted = Boolean.FALSE;

public Session(final Long memberId) {
Expand All @@ -43,7 +44,7 @@ public static Session of(final Long memberId) {
}

public boolean isValid() {
if (this.deleted == Boolean.TRUE) {
if (!this.isLoggedIn) {
return false;
}
// TODO: 현재는 만료 시간만 체크중이지만, 이후에 IP 등 다양한 검증 로직 추가
Expand All @@ -57,6 +58,6 @@ public void extendTime() {
}

public void logout() {
this.deleted = Boolean.TRUE;
this.isLoggedIn = Boolean.FALSE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ default Session getById(final Long id) {
return session.get();
}

default Session getByMemberId(final Long memberId) {
final Optional<Session> session = findByMemberId(memberId);
default Session getByMemberIdAndIsLoggedInTrue(final Long memberId) {
final Optional<Session> session = findByMemberIdAndIsLoggedInTrue(memberId);
if (session.isEmpty()) {
new AuthException();
}
return session.get();
}

Optional<Session> findByMemberId(Long memberId);
Optional<Session> findByMemberId(final Long memberId);

Optional<Session> findByMemberIdAndIsLoggedInTrue(final Long memberId);
}

0 comments on commit 8cee305

Please sign in to comment.