Skip to content

Commit

Permalink
feat : 회원가입시 refreshToKen 반환 #15
Browse files Browse the repository at this point in the history
  • Loading branch information
PicturePark1101 committed May 30, 2024
1 parent ec15cef commit 2259b71
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public class SecurityConfig {
private final CustomJwtAuthenticationEntryPoint customJwtAuthenticationEntryPoint;
private final CustomAccessDeniedHandler customAccessDeniedHandler;


private static final String[] AUTH_WHITE_LIST = {"/api/v1/member"};
private static final String[] AUTH_WHITE_LIST = {"/api/v1/members"};

@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@
public class JwtTokenProvider {

private static final String USER_ID = "userId";

private static final Long ACCESS_TOKEN_EXPIRATION_TIME = 24 * 60 * 60 * 1000L * 14;
private static final Long ACCESS_TOKEN_EXPIRATION_TIME = 60 * 60 * 1000L;
private static final Long REFRESH_TOKEN_EXPIRATION_TIME = 60 * 60 * 24 * 1000L * 14;

@Value("${jwt.secret}")
private String JWT_SECRET;


public String issueAccessToken(final Authentication authentication) {
return generateToken(authentication, ACCESS_TOKEN_EXPIRATION_TIME);
}

public String issueRefreshToken(final Authentication authentication) {
return generateToken(authentication, REFRESH_TOKEN_EXPIRATION_TIME);
}

public String generateToken(Authentication authentication, Long tokenExpirationTime) {
final Date now = new Date();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.example.demo.controller;

import com.example.demo.service.MemberService;
import com.example.demo.service.dto.UserJoinResponse;
import com.example.demo.service.dto.member.UserJoinResponse;
import com.example.demo.service.dto.member.MemberCreateDto;
import com.example.demo.service.dto.member.MemberFindDto;
import java.net.URI;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -49,5 +48,4 @@ public ResponseEntity deleteMember(
memberService.deleteMemberById(memberId);
return ResponseEntity.noContent().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import com.example.demo.domain.Member;
import com.example.demo.exception.NotFoundException;
import com.example.demo.repository.MemberRepository;
import com.example.demo.service.dto.UserJoinResponse;
import com.example.demo.service.dto.member.UserJoinResponse;
import com.example.demo.service.dto.member.MemberCreateDto;
import com.example.demo.service.dto.member.MemberFindDto;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties.Lettuce.Cluster.Refresh;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -32,7 +33,11 @@ public UserJoinResponse createMember(
String accessToken = jwtTokenProvider.issueAccessToken(
UserAuthentication.createUserAuthentication(memberId)
);
return UserJoinResponse.of(accessToken, memberId.toString());
String refreshToekn = jwtTokenProvider.issueRefreshToken(
UserAuthentication.createUserAuthentication(memberId)
);
return UserJoinResponse.of( memberId.toString(), accessToken, refreshToekn);

}

public Member findById(Long memberId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.example.demo.service.dto.member;

public record UserJoinResponse(
String userId,
String accessToken,
String refreshToekn,
String userId
String refreshToekn
) {

public static UserJoinResponse of(
String userId,
String accessToken,
String refreshToekn,
String userId
String refreshToekn
) {
return new UserJoinResponse(accessToken, refreshToekn, userId);
return new UserJoinResponse(userId, accessToken, refreshToekn);
}
}

0 comments on commit 2259b71

Please sign in to comment.