Skip to content

Commit bdf7bbb

Browse files
committed
🐛 fix: 관리자 로그인 성공 시, last_login 업데이트
1 parent 45de049 commit bdf7bbb

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

backend/src/main/java/io/f1/backend/domain/admin/app/handler/AdminLoginSuccessHandler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import static io.f1.backend.domain.user.constants.SessionKeys.ADMIN;
44
import static io.f1.backend.global.util.SecurityUtils.getCurrentAdminPrincipal;
55

6+
import io.f1.backend.domain.admin.dao.AdminRepository;
67
import io.f1.backend.domain.admin.dto.AdminPrincipal;
8+
import io.f1.backend.domain.admin.entity.Admin;
79
import jakarta.servlet.http.HttpServletRequest;
810
import jakarta.servlet.http.HttpServletResponse;
911
import jakarta.servlet.http.HttpSession;
12+
import java.time.LocalDateTime;
1013
import lombok.RequiredArgsConstructor;
1114
import org.springframework.security.core.Authentication;
1215
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
@@ -16,6 +19,7 @@
1619
@RequiredArgsConstructor
1720
public class AdminLoginSuccessHandler implements AuthenticationSuccessHandler {
1821

22+
private final AdminRepository adminRepository;
1923
private final HttpSession httpSession;
2024

2125
@Override
@@ -25,6 +29,11 @@ public void onAuthenticationSuccess(
2529
Authentication authentication) {
2630

2731
AdminPrincipal principal = getCurrentAdminPrincipal();
32+
Admin admin = adminRepository.findByUsername(principal.getUsername())
33+
.orElseThrow(() -> new RuntimeException("E404007: 존재하지 않는 관리자입니다."));
34+
35+
admin.updateLastLogin(LocalDateTime.now());
36+
adminRepository.save(admin);
2837
httpSession.setAttribute(ADMIN, principal.getAuthenticationAdmin());
2938

3039
response.setStatus(HttpServletResponse.SC_OK); // 200

backend/src/main/java/io/f1/backend/domain/admin/entity/Admin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ public class Admin extends BaseEntity {
2727

2828
@Column(nullable = false)
2929
private LocalDateTime lastLogin;
30+
31+
public void updateLastLogin(LocalDateTime lastLogin) {
32+
this.lastLogin = lastLogin;
33+
}
3034
}

0 commit comments

Comments
 (0)