Skip to content
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

[기본과제/심화과제] 6주차 JWT 토큰 구현 #4

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

hayounSong
Copy link
Collaborator

SERVER PR


JWT 토큰 및 Redis를 이용한 RefreshToken을 살짝 구현해보았습니다.

🐕 과제 구현 명세

  • JWT를 이용한 accessToken 발급 과정을 구현했어요
  • Redis와 RefreshToken을.. 조금 건드려봤습니다

🐥 이런 점이 새로웠어요 / 어려웠어요

  • Redis 어렵네요..

Copy link

@2zerozu 2zerozu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!!

Comment on lines +27 to +32
@Bean
public RedisTemplate<?, ?> redisTemplate() {
RedisTemplate<byte[], byte[]> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory());
return redisTemplate;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제네릭 고수 ..

Comment on lines +7 to +8
@Id
private String refreshToken;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memberId가 아니라 refreshToken에 id 어노테이션을 붙여주네요??

ValueOperations<String,Long> valueOperations= redisTemplate.opsForValue();
Long memberId=valueOperations.get(refreshToken);

if(Objects.isNull(memberId)){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맨날 if(memberId==null) 썼는데 Objects.isNull()로도 사용할 수 있네요!! 배워갑니다

*/
NOT_FOUND_USER_EXCEPTION(HttpStatus.NOT_FOUND, "존재하지 않는 유저입니다"),
NOT_FOUND_POST_EXCEPTION(HttpStatus.NOT_FOUND, "존재하지 않는 게시물입니다"),
NOT_FOUND_EMOTION_EXCEPTION(HttpStatus.NOT_FOUND, "존재하지 않는 감정 기록입니다"),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

쇽샥이슈


import sopt.org.fourthSixSeminar.exception.Error;

public class BadRequestException extends sopt.org.fourthSeminar.exception.model.SoptException {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SoptException import해주면 어떨깝쇼

Comment on lines +6 to +7
public BadRequestException(Error error, String message) {
super(error, message);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    public BadRequestException(ErrorType error) {
        super(error, error.getMessage());
    }

이렇게 쓰면 아래 Service단에서 ...더보기

@Transactional
public UserResponseDto create(UserRequestDto request) {
if (userRepository.existsByEmail(request.getEmail())) {
throw new ConflictException(Error.ALREADY_EXIST_USER_EXCEPTION, Error.ALREADY_EXIST_USER_EXCEPTION.getMessage());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConflictException(Error.ALREADY_EXIST_USER_EXCEPTION)
개인적으로 이렇게 쓰면 더 가독성있어보이는거같아요!!

2zerozu

This comment was marked as duplicate.

@hayounSong hayounSong changed the title [기본과제] 6주차 JWT 토큰 구현 [기본과제/심화과제] 6주차 JWT 토큰 구현 Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants