Skip to content

Commit

Permalink
Fear: change Date logic
Browse files Browse the repository at this point in the history
  • Loading branch information
minseokey committed May 20, 2024
1 parent 48ca453 commit c039677
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ public void deleteUser(String token) {
} catch (Exception e) {
throw new AccessTokenNotValidException("토큰이 유효하지 않습니다.");
}
userRepository.deleteByEmail(jwtTokenProvider.getEmailForAccessToken(token));
User user = userRepository.findByEmail(jwtTokenProvider.getEmailForAccessToken(token)).orElseThrow(
() -> new NotExistUserException("사용자를 찾을 수 없습니다.")
);
if (user.getProfileImageUrl() != null) {
s3Uploader.delete(user.getProfileImageUrl());
}
userRepository.delete(user);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public String upload(String dirName, MultipartFile fileData) {
public void delete(String fileName) {
try{
String decodedFileName = URLDecoder.decode(fileName, StandardCharsets.UTF_8);
s3Client.deleteObject(bucket, decodedFileName);
String[] pathParts = decodedFileName.split("/");

String key = pathParts[pathParts.length - 2] + "/" + pathParts[pathParts.length - 1];
s3Client.deleteObject(bucket, key);
}
catch (Exception e){
throw new S3IOException("S3 파일 삭제에 실패하였습니다.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.jsonwebtoken.*;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.UUID;

Expand All @@ -32,12 +33,12 @@ public String fromHeader(String header) {
public String createAccessToken(String userId, String role) {
Claims claims = Jwts.claims().setSubject(userId);
claims.put("role", role);
log.info("현재시간" + System.currentTimeMillis() + (9 * 60 * 60 * 1000));

Date now = new Date();
return JwtPrefix + Jwts.builder()
.setClaims(claims)
.setIssuedAt(new Date())
.setExpiration(new Date(System.currentTimeMillis() + accessTokenExpiration + (9 * 60 * 60 * 1000)))
.setIssuedAt(now)
.setExpiration(new Date(now.getTime() + accessTokenExpiration))
.signWith(SignatureAlgorithm.HS256, secretKey)
.compact();
}
Expand Down

0 comments on commit c039677

Please sign in to comment.