Skip to content

Commit

Permalink
Merge pull request #102 from IxxP-Girls/modify
Browse files Browse the repository at this point in the history
#10 Fix: 토큰을 쿠키로 보내게 수정
  • Loading branch information
diddnwjd authored Mar 11, 2024
2 parents 400bcef + e8c6eb9 commit 98cdfba
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/java/com/ixxp/culpop/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.ixxp.culpop.util.jwtutil.JwtUtil;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseCookie;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
Expand Down Expand Up @@ -50,7 +51,15 @@ public void loginAdmin(AdminLoginRequest adminLoginRequest, HttpServletResponse
// accessToken 생성
String accessToken = jwtUtil.createAdminToken(email, admin.getRole());

// Header 로 토큰 반환
response.addHeader(JwtUtil.AUTHORIZATION_HEADER, accessToken);
// Cookie 로 accessToken 반환
ResponseCookie cookie = ResponseCookie.from("AccessToken", accessToken)
.path("/")
.maxAge(7 * 24 * 60 * 60) // 7일
.httpOnly(true)
.secure(true)
.sameSite("None")
// .domain("culpop.shop")
.build();
response.addHeader("Set-Cookie", cookie.toString());
}
}

0 comments on commit 98cdfba

Please sign in to comment.