Set cookie
This commit is contained in:
@@ -5,6 +5,8 @@ import demo.api.user.domain.User;
|
|||||||
import demo.api.user.dtos.UserSignInRequest;
|
import demo.api.user.dtos.UserSignInRequest;
|
||||||
import demo.api.user.dtos.UserSignUpRequest;
|
import demo.api.user.dtos.UserSignUpRequest;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import javax.servlet.http.Cookie;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@@ -45,7 +47,17 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/signIn")
|
@PostMapping("/signIn")
|
||||||
public ResponseEntity<TokenDto> signIn(@Validated UserSignInRequest signInReq) {
|
public String signIn(@Validated UserSignInRequest signInReq, HttpServletResponse res) {
|
||||||
return authService.signIn(signInReq);
|
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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,14 +40,9 @@ public class SecurityConfig {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
//
|
// Disable csrf to use token
|
||||||
http
|
http
|
||||||
.csrf().disable();
|
.csrf().disable();
|
||||||
// .formLogin()
|
|
||||||
// .loginPage("/auth/signIn")
|
|
||||||
// .usernameParameter("email")
|
|
||||||
// .defaultSuccessUrl("/")
|
|
||||||
// .failureUrl("/auth/signIn?fail=true");
|
|
||||||
|
|
||||||
//
|
//
|
||||||
http
|
http
|
||||||
|
|||||||
Reference in New Issue
Block a user