Skip to content
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

fix: logout 에러 수정 #146

Merged
merged 1 commit into from
Mar 13, 2024
Merged
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
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);
}