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

[BE-55] feat : 토큰 쿠키에 담아 보내기 #166

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import com.econovation.recruitdomain.domains.interviewer.domain.Role;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -54,8 +57,20 @@ public ResponseEntity<TokenResponse> issueToken() {

@Operation(summary = "로그인합니다.", description = "accessToken, refreshToken을 발급합니다.")
@PostMapping("/login")
public ResponseEntity<TokenResponse> login(@RequestBody LoginRequestDto loginRequestDto) {
public ResponseEntity<TokenResponse> login(@RequestBody LoginRequestDto loginRequestDto, HttpServletResponse response) {
TokenResponse tokenResponse = userLoginUseCase.execute(loginRequestDto);
Cookie accessCookie = new Cookie("ACCESSTOKEN", tokenResponse.getAccessToken());
Copy link
Collaborator

Choose a reason for hiding this comment

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

ACCESS_TOKEN으로 바꿔주세요

accessCookie.setHttpOnly(true);
accessCookie.setPath("/");
accessCookie.setMaxAge(60 * 60 * 24 * 30);
response.addCookie(accessCookie);

Cookie refreshCookie = new Cookie("REFRESHTOKEN", tokenResponse.getRefreshToken());
Copy link
Collaborator

Choose a reason for hiding this comment

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

REFRESH_TOKEN으로 바꿔주세요

accessCookie.setHttpOnly(true);
accessCookie.setPath("/");
accessCookie.setMaxAge(60 * 60 * 24 * 30);
response.addCookie(refreshCookie);

return new ResponseEntity<>(tokenResponse, HttpStatus.OK);
}

Expand Down
Loading