-
Notifications
You must be signed in to change notification settings - Fork 2
[Auth] Redis 도입 및 피드백 리팩토링 #53
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f15575f
chore: Redis 포트 설정 및 PassWordEncoder 분리
larama-C 988f03b
refactor: DTO 검증 로직 추가
larama-C ec6443d
refactor: DTO 검증 로직 추가
larama-C 895e267
refactor: Validation 예외 전역 처리 추가
larama-C bef88eb
feat: 리프레쉬 토큰, 인증 코드 Redis로 이관 및 토큰 재발급 로직 수정
larama-C df7b8c0
fix: Github CI 테스트 Redis 경로 추가
larama-C File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/com/back/web7_9_codecrete_be/domain/auth/dto/request/EmailSendRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,13 @@ | ||
| package com.back.web7_9_codecrete_be.domain.auth.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.Email; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class EmailSendRequest { | ||
|
|
||
| @NotBlank(message = "이메일은 필수입니다.") | ||
| @Email(message = "이메일 형식이 올바르지 않습니다.") | ||
| private String email; | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
src/main/java/com/back/web7_9_codecrete_be/domain/auth/dto/request/EmailVerifyRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,21 @@ | ||
| package com.back.web7_9_codecrete_be.domain.auth.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.Email; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Pattern; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class EmailVerifyRequest { | ||
|
|
||
| @NotBlank(message = "이메일은 필수입니다.") | ||
| @Email(message = "이메일 형식이 올바르지 않습니다.") | ||
| private String email; | ||
|
|
||
| @NotBlank(message = "인증 코드는 필수입니다.") | ||
| @Pattern( | ||
| regexp = "^[A-Z0-9]{6}$", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 정규표현식 처리하신 것 잘하신 것 같습니다. |
||
| message = "인증 코드는 영문 대문자와 숫자를 포함한 6자리여야 합니다." | ||
| ) | ||
| private String code; | ||
| } | ||
5 changes: 5 additions & 0 deletions
5
src/main/java/com/back/web7_9_codecrete_be/domain/auth/dto/request/LoginRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,19 @@ | ||
| package com.back.web7_9_codecrete_be.domain.auth.dto.request; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.Email; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @Schema(description = "로그인 요청 DTO") | ||
| public class LoginRequest { | ||
| @NotBlank(message = "이메일은 필수입니다.") | ||
| @Email(message = "이메일 형식이 올바르지 않습니다.") | ||
| @Schema(description = "사용자 이메일", example = "test@example.com") | ||
| private String email; | ||
|
|
||
| @NotBlank(message = "비밀번호는 필수입니다.") | ||
| @Schema(description = "비밀번호", example = "1234abcd!") | ||
| private String password; | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/back/web7_9_codecrete_be/domain/auth/dto/request/SignupRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/back/web7_9_codecrete_be/domain/auth/entity/RefreshToken.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.back.web7_9_codecrete_be.domain.auth.entity; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class RefreshToken { | ||
|
|
||
| private Long userId; // 사용자 ID | ||
| private String refreshToken; // 실제 토큰 값 | ||
| private long expiration; // TTL (초 단위) | ||
| } |
37 changes: 37 additions & 0 deletions
37
...java/com/back/web7_9_codecrete_be/domain/auth/repository/RefreshTokenRedisRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.back.web7_9_codecrete_be.domain.auth.repository; | ||
|
|
||
| import com.back.web7_9_codecrete_be.domain.auth.entity.RefreshToken; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.redis.core.RedisTemplate; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class RefreshTokenRedisRepository { | ||
| private final RedisTemplate<String, String> redisTemplate; | ||
|
|
||
| private static final String REFRESH_TOKEN_PREFIX = "refreshToken: "; | ||
|
|
||
| public void save(RefreshToken refreshToken) { | ||
| redisTemplate.opsForValue().set( | ||
| REFRESH_TOKEN_PREFIX + refreshToken.getUserId(), | ||
| refreshToken.getRefreshToken(), | ||
| refreshToken.getExpiration(), | ||
| TimeUnit.SECONDS | ||
| ); | ||
| } | ||
|
|
||
| public String findByUserId(Long userId) { | ||
| return (String) redisTemplate.opsForValue().get(REFRESH_TOKEN_PREFIX + userId); | ||
| } | ||
|
|
||
| public void deleteByUserId(Long userId){ | ||
| redisTemplate.delete(REFRESH_TOKEN_PREFIX + userId); | ||
| } | ||
|
|
||
| public boolean existsByUserId(Long userId) { | ||
| return redisTemplate.hasKey(REFRESH_TOKEN_PREFIX + userId); | ||
| } | ||
| } |
9 changes: 0 additions & 9 deletions
9
...main/java/com/back/web7_9_codecrete_be/domain/auth/repository/RefreshTokenRepository.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...com/back/web7_9_codecrete_be/domain/email/repository/VerificationCodeRedisRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.back.web7_9_codecrete_be.domain.email.repository; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.redis.core.RedisTemplate; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class VerificationCodeRedisRepository { | ||
|
|
||
| private final RedisTemplate<String, String> redisTemplate; | ||
|
|
||
| private static final String PREFIX = "email:verify:"; | ||
|
|
||
| public void save(String email, String code, long ttlSeconds) { | ||
| redisTemplate.opsForValue().set( | ||
| PREFIX + email, | ||
| code, | ||
| ttlSeconds, | ||
| TimeUnit.SECONDS | ||
| ); | ||
| } | ||
|
|
||
| public String findByEmail(String email) { | ||
| return redisTemplate.opsForValue().get(PREFIX + email); | ||
| } | ||
|
|
||
| public void deleteByEmail(String email) { | ||
| redisTemplate.delete(PREFIX + email); | ||
| } | ||
|
|
||
| public boolean existsByEmail(String email) { | ||
| return redisTemplate.hasKey(PREFIX + email); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Email어노테이션은 생각보다 검증을 탄탄해주게 하지 않아서 해당 부분은 정규식으로 수정하는 게 좋을 것 같습니다.관련 링크
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확인했습니다! 추후 반영하겠습니다!