Skip to content

Commit

Permalink
๐Ÿš€ Merge pull request #37 from local-mood/fix/33-auth-api
Browse files Browse the repository at this point in the history
Fix: ํšŒ์› API ๋ฏธ์ž‘๋™ ์˜ค๋ฅ˜ ์ˆ˜์ • (1์ฐจ)
  • Loading branch information
gmkim20713 authored Dec 22, 2023
2 parents f362569 + 8632130 commit f2792fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
28 changes: 16 additions & 12 deletions src/main/java/com/ceos/vote/auth/controller/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.ceos.vote.auth.dto.SignupRequestDto;

import com.ceos.vote.common.dto.ResponseDto;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.web.server.Cookie;
Expand All @@ -23,9 +24,9 @@ public class AuthController {

// ํšŒ์›๊ฐ€์ž…
@PostMapping("/signup")
public ResponseEntity<?> join(@RequestBody @Valid SignupRequestDto requestDto) {
authService.joinMember(requestDto);
return ResponseDto.ok();
public ResponseEntity<?> join(@RequestBody @Valid SignupRequestDto signupRequest) {

return ResponseDto.ok(authService.joinMember(signupRequest));
}

// ๋กœ๊ทธ์ธ
Expand All @@ -40,15 +41,16 @@ public ResponseEntity<?> login(@RequestBody LoginRequestDto loginRequest) {
.secure(true)
.sameSite(Cookie.SameSite.NONE.attributeValue()) //์„œ๋“œํŒŒํ‹ฐ ์ฟ ํ‚ค ์‚ฌ์šฉ ํ—ˆ์šฉ
.build();
return ResponseEntity.ok()
.header(HttpHeaders.SET_COOKIE, httpCookie.toString())
.header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenDto.getAccessToken())
.build();

return ResponseDto.ok(tokenDto);
}

// ํ† ํฐ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ
@PostMapping("/validate")
public ResponseEntity<?> validate(@RequestHeader("Authorization") String requestAccessToken) {
public ResponseEntity<?> validate(HttpServletRequest request) {

String requestAccessToken = request.getHeader(HttpHeaders.AUTHORIZATION);

if (!authService.validate(requestAccessToken)) {
return ResponseEntity.ok().build();
} else {
Expand All @@ -58,8 +60,9 @@ public ResponseEntity<?> validate(@RequestHeader("Authorization") String request

// ํ† ํฐ ์žฌ๋ฐœ๊ธ‰
@PostMapping("/reissue")
public ResponseEntity<?> reissue(@CookieValue(name = "refresh-token") String requestRefreshToken,
@RequestHeader("Authorization") String requestAccessToken) {
public ResponseEntity<?> reissue(@CookieValue(name = "refresh-token") String requestRefreshToken, HttpServletRequest request) {

String requestAccessToken = request.getHeader(HttpHeaders.AUTHORIZATION);

TokenDto newAuthToken = authService.reissue(requestAccessToken, requestRefreshToken);

Expand Down Expand Up @@ -90,7 +93,9 @@ public ResponseEntity<?> reissue(@CookieValue(name = "refresh-token") String req

// ๋กœ๊ทธ์•„์›ƒ
@PostMapping("/logout")
public ResponseEntity<?> logout(@RequestHeader("Authorization") String requestAccessToken) {
public ResponseEntity<?> logout(HttpServletRequest request) {

String requestAccessToken = request.getHeader(HttpHeaders.AUTHORIZATION);

// Access Token์„ ๋ฌดํšจํ™”ํ•˜์—ฌ ๋กœ๊ทธ์•„์›ƒ ์ฒ˜๋ฆฌ
authService.logout(requestAccessToken);
Expand All @@ -100,7 +105,6 @@ public ResponseEntity<?> logout(@RequestHeader("Authorization") String requestAc
.path("/")
.build();


return ResponseEntity.status(HttpStatus.OK)
.header(HttpHeaders.SET_COOKIE, responseCookie.toString())
.build();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/ceos/vote/auth/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class AuthService {

// ํšŒ์›๊ฐ€์ž…
@Transactional
public void joinMember(SignupRequestDto requestDto) {
public Member joinMember(SignupRequestDto requestDto) {

// ์ด๋ฉ”์ผ, ID ์ค‘๋ณต ๊ฒ€์‚ฌ
if (findUserByEmail(requestDto.getEmail()))
Expand All @@ -49,6 +49,8 @@ public void joinMember(SignupRequestDto requestDto) {

Member member = requestDto.toMember(passwordEncoder, teamRepository);
memberRepository.save(member);

return member;
}


Expand Down

0 comments on commit f2792fb

Please sign in to comment.