Set cookie

This commit is contained in:
hou27
2022-06-11 01:54:45 +09:00
parent cb9d35afd9
commit fe53bc9ef0
2 changed files with 15 additions and 8 deletions

View File

@@ -5,6 +5,8 @@ import demo.api.user.domain.User;
import demo.api.user.dtos.UserSignInRequest;
import demo.api.user.dtos.UserSignUpRequest;
import java.util.Objects;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
@@ -45,7 +47,17 @@ public class AuthController {
}
@PostMapping("/signIn")
public ResponseEntity<TokenDto> signIn(@Validated UserSignInRequest signInReq) {
return authService.signIn(signInReq);
public String signIn(@Validated UserSignInRequest signInReq, HttpServletResponse res) {
ResponseEntity<TokenDto> tokenDtoResponseEntity = authService.signIn(signInReq);
Cookie cookie = new Cookie(
"access_token",
tokenDtoResponseEntity.getBody().getAccess_token()
);
cookie.setPath("/");
cookie.setMaxAge(Integer.MAX_VALUE);
res.addCookie(cookie);
return "redirect:/user/profile";
}
}

View File

@@ -40,14 +40,9 @@ public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
//
// Disable csrf to use token
http
.csrf().disable();
// .formLogin()
// .loginPage("/auth/signIn")
// .usernameParameter("email")
// .defaultSuccessUrl("/")
// .failureUrl("/auth/signIn?fail=true");
//
http