diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/user/domain/AuthCode.java b/src/main/java/com/kusithm/hdmedi_server/domain/user/domain/AuthCode.java index a62e783..11240ee 100644 --- a/src/main/java/com/kusithm/hdmedi_server/domain/user/domain/AuthCode.java +++ b/src/main/java/com/kusithm/hdmedi_server/domain/user/domain/AuthCode.java @@ -12,13 +12,13 @@ @RedisHash(value = "authCode", timeToLive = 604800000) public class AuthCode { @Id - private String authCode; - private Long id; + private String id; + private Long value; public static AuthCode createAuthCode(String authCode, Long id){ return AuthCode.builder() - .authCode(authCode) - .id(id) + .id(authCode) + .value(id) .build(); } } diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/user/repository/AuthCodeRepository.java b/src/main/java/com/kusithm/hdmedi_server/domain/user/repository/AuthCodeRepository.java index 0f95d1d..001e3f7 100644 --- a/src/main/java/com/kusithm/hdmedi_server/domain/user/repository/AuthCodeRepository.java +++ b/src/main/java/com/kusithm/hdmedi_server/domain/user/repository/AuthCodeRepository.java @@ -5,8 +5,8 @@ import java.util.Optional; -public interface AuthCodeRepository extends CrudRepository { - Optional findByAuthCode(String AuthCode); +public interface AuthCodeRepository extends CrudRepository { + Optional findById(String id); - boolean existsByAuthCode(String authCode); + boolean existsById(String id); } diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/user/service/AuthService.java b/src/main/java/com/kusithm/hdmedi_server/domain/user/service/AuthService.java index 0b803f8..ddb5604 100644 --- a/src/main/java/com/kusithm/hdmedi_server/domain/user/service/AuthService.java +++ b/src/main/java/com/kusithm/hdmedi_server/domain/user/service/AuthService.java @@ -64,12 +64,12 @@ public AuthCodeResponseDto createAuthCode(HDmediUser hDmediUser) { String authCode = createAuthCodeAtSecureRandom(new SecureRandom()); AuthCode createdAuthCode = AuthCode.createAuthCode(authCode, hDmediUser.getId()); saveAuthCode(createdAuthCode); - return AuthCodeResponseDto.of(createdAuthCode.getAuthCode()); + return AuthCodeResponseDto.of(createdAuthCode.getId()); } public GuestSignInResponseDto geustSignIn(String authCode) { AuthCode findAuthCode = getUserFromAuthCode(authCode); - User findUser = getUserFromId(findAuthCode.getId()); + User findUser = getUserFromId(findAuthCode.getValue()); Token issuedToken = issueAccessTokenAndRefreshToken(findUser, Boolean.TRUE); return GuestSignInResponseDto.of(findUser, findUser.getChildren(), issuedToken.getAccessToken()); } @@ -80,7 +80,8 @@ private User getUserFromId(Long userId) { } private AuthCode getUserFromAuthCode(String authCode) { - return authCodeRepository.findByAuthCode(authCode) + String AuthCodeId = jwtProvider.deletePrefixOfToken(authCode); + return authCodeRepository.findById(AuthCodeId) .orElseThrow(() -> new UnauthorizedException(INVALID_AUTH_CODE)); } @@ -89,7 +90,7 @@ private void saveAuthCode(AuthCode createdAuthCode) { } private boolean duplicateAuthCode(String authCode) { - return authCodeRepository.existsByAuthCode(authCode); + return authCodeRepository.existsById(authCode); } private String createAuthCodeAtSecureRandom(SecureRandom random) { diff --git a/src/main/java/com/kusithm/hdmedi_server/global/config/jwt/JwtProvider.java b/src/main/java/com/kusithm/hdmedi_server/global/config/jwt/JwtProvider.java index c684546..8fe7363 100644 --- a/src/main/java/com/kusithm/hdmedi_server/global/config/jwt/JwtProvider.java +++ b/src/main/java/com/kusithm/hdmedi_server/global/config/jwt/JwtProvider.java @@ -10,6 +10,7 @@ import lombok.Getter; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; import java.security.Key; import java.util.Base64; @@ -35,6 +36,10 @@ public Token issueToken(HDmediUser hDmediUser) { return responseToken; } + public String deletePrefixOfToken(String token){ + return StringUtils.delete(token, "Bearer "); + } + public void validateAccessToken(String accessToken) { try { getJwtParser().parseClaimsJws(accessToken);