Skip to content

Commit

Permalink
♻️ 코드 수정: 프론트엔드 배포 연동 - 만료 시간 연장 기능 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
JoJeHuni committed Dec 5, 2024
1 parent b4a8407 commit b4a55b8
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import intbyte4.learnsmate.admin.service.AdminService;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

Expand All @@ -22,10 +21,8 @@
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -106,6 +103,10 @@ protected void successfulAuthentication(HttpServletRequest request, HttpServletR
// JWT 생성
JwtTokenDTO tokenDTO = new JwtTokenDTO(userCode, userEmail, userName);
String token = jwtUtil.generateToken(tokenDTO, roles, null, authResult);

// 만료 시간 계산 및 추가
Date expirationDate = jwtUtil.getExpirationDateFromToken(token);
long expTimestamp = expirationDate.getTime();
String refreshToken = jwtUtil.generateRefreshToken(tokenDTO);
log.info("토큰 생성 완료");

Expand All @@ -120,6 +121,7 @@ protected void successfulAuthentication(HttpServletRequest request, HttpServletR
Map<String, Object> responseData = new HashMap<>();
responseData.put("accessToken", token);
responseData.put("refreshToken", refreshToken);
responseData.put("exp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(expirationDate));
responseData.put("name", userName);
responseData.put("code", userCode);
responseData.put("adminDepartment", userDetails.getUserDTO().getAdminDepartment());
Expand Down

0 comments on commit b4a55b8

Please sign in to comment.