Skip to content

Commit

Permalink
#33 - Feat: 로그인 성공시 응답 헤더, 바디에 모두 accessToken 담아 응답보내기
Browse files Browse the repository at this point in the history
  • Loading branch information
ahah525 committed Nov 8, 2022
1 parent c26d357 commit 1e1c454
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.example.mutbooks.app.member.service.MemberService;
import com.example.mutbooks.util.Ut;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -39,12 +38,15 @@ public ResponseEntity<RsData> login(@RequestBody LoginDto loginDto) {
return Ut.spring.responseEntityOf(RsData.of("F-3", "비밀번호가 일치하지 않습니다."));
}

// 헤더(Authentication) 에 JWT 토큰 & 바디에 username, password
HttpHeaders headers = new HttpHeaders();
headers.set("Authentication", "JWT Token");

String body = "username : %s, password : %s".formatted(loginDto.getUsername(), loginDto.getPassword());

return Ut.spring.responseEntityOf(RsData.of("S-1", "로그인 성공, JWT AccessToken 을 발급합니다."), headers);
String accessToken = "JWT Access Token";
// 응답 헤더, 바디에 accessToken 담기
return Ut.spring.responseEntityOf(
RsData.of(
"S-1",
"로그인 성공, JWT AccessToken 을 발급합니다.",
Ut.mapOf("Authentication", accessToken)
),
Ut.spring.httpHeadersOf("Authentication", accessToken)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ public class RsData<T> {
private String msg;
private T data;

public static <T> RsData<T> of(String resultCode, String msg, T data) {
return new RsData<>(resultCode, msg, data);
}

public static <T> RsData<T> of(String resultCode, String msg) {
return new RsData<>(resultCode, msg, null);
return of(resultCode, msg, null);
}

public boolean isSuccess() {
Expand Down

0 comments on commit 1e1c454

Please sign in to comment.