Skip to content

Commit

Permalink
[NO_JIRA] JwtTokenResponse 추가 (#57)
Browse files Browse the repository at this point in the history
* feat : JwtTokenResponse 구현

* refactor : 1년 동안 유요한 토큰 발급

* refactor : Jwt 토큰을 바디에 리턴하도록 변경
  • Loading branch information
wjdwnsdnjs13 authored Jul 19, 2024
1 parent 4df209f commit 23c1d22
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.depromeet.spot.domain.member.Member;
import org.depromeet.spot.domain.member.enums.MemberRole;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;

import io.jsonwebtoken.Claims;
Expand All @@ -34,15 +33,11 @@ public class JwtTokenUtil {
@Value("${spring.jwt.secret}")
private String SECRETKEY;

public HttpHeaders getJWTToken(Member member) {
public String getJWTToken(Member member) {
// TODO 토큰 구현하기.

// jwt 토큰 생성
String token = generateToken(member.getId(), member.getRole());

HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.AUTHORIZATION, "Bearer " + token);
return headers;
return generateToken(member.getId(), member.getRole());
}

public String generateToken(Long memberId, MemberRole memberRole) {
Expand All @@ -53,7 +48,8 @@ public String generateToken(Long memberId, MemberRole memberRole) {
.setIssuedAt(new Date(System.currentTimeMillis()))
.setExpiration(
new Date(
System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 30L)) // 토큰 만료 시간
System.currentTimeMillis()
+ 1000 * 60 * 60 * 24 * 30 * 12L)) // 토큰 만료 시간
.signWith(SignatureAlgorithm.HS256, SECRETKEY.getBytes())
.compact();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import org.depromeet.spot.application.common.jwt.JwtTokenUtil;
import org.depromeet.spot.application.member.dto.request.RegisterReq;
import org.depromeet.spot.application.member.dto.response.JwtTokenResponse;
import org.depromeet.spot.domain.member.Member;
import org.depromeet.spot.usecase.port.in.member.MemberUsecase;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -36,25 +36,25 @@ public class MemberController {
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "Member 회원가입 API")
public HttpHeaders create(@RequestBody @Valid RegisterReq request) {
public JwtTokenResponse create(@RequestBody @Valid RegisterReq request) {

Member member = request.toDomain();
Member memberResult = memberUsecase.create(member);

return jwtTokenUtil.getJWTToken(memberResult);
return new JwtTokenResponse(jwtTokenUtil.getJWTToken(memberResult));
}

@GetMapping("/{idCode}")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "Member 로그인 API")
public HttpHeaders login(
public JwtTokenResponse login(
@PathVariable("idCode")
@Parameter(name = "idCode", description = "sns idCode", required = true)
String idCode) {

Member member = memberUsecase.login(idCode);

return jwtTokenUtil.getJWTToken(member);
return new JwtTokenResponse(jwtTokenUtil.getJWTToken(member));
}

@GetMapping("/duplicatedNickname/{nickname}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.depromeet.spot.application.member.dto.response;

public record JwtTokenResponse(String jwtToken) {}

This file was deleted.

0 comments on commit 23c1d22

Please sign in to comment.