-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f2936f
commit c674437
Showing
66 changed files
with
1,788 additions
and
1,941 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 21 additions & 22 deletions
43
src/main/java/com/khu/gitbox/auth/config/WebMvcConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,36 @@ | ||
package com.khu.gitbox.auth.config; | ||
|
||
import java.util.Arrays; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import java.util.Arrays; | ||
|
||
@Slf4j | ||
@Configuration | ||
@RequiredArgsConstructor | ||
public class WebMvcConfig implements WebMvcConfigurer { | ||
|
||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
log.info("CORS 설정 적용"); | ||
registry.addMapping("/**") | ||
.allowedOrigins(getAllowOrigins()) | ||
.allowedHeaders("*") | ||
.allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS") | ||
.allowCredentials(true); | ||
} | ||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
log.info("CORS 설정 적용"); | ||
registry.addMapping("/**") | ||
.allowedOrigins(getAllowOrigins()) | ||
.allowedHeaders("*") | ||
.allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS") | ||
.allowCredentials(true); | ||
} | ||
|
||
private String[] getAllowOrigins() { | ||
return Arrays.asList( | ||
"http://localhost", | ||
"http://localhost:3000", | ||
"http://localhost:1234", | ||
"http://localhost:5173", | ||
"http://125.250.17.196:1234" | ||
).toArray(String[]::new); | ||
} | ||
private String[] getAllowOrigins() { | ||
return Arrays.asList( | ||
"http://localhost", | ||
"http://localhost:3000", | ||
"http://localhost:1234", | ||
"http://localhost:5173", | ||
"http://125.250.17.196:1234" | ||
).toArray(String[]::new); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 17 additions & 19 deletions
36
src/main/java/com/khu/gitbox/auth/presentation/AuthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,35 @@ | ||
package com.khu.gitbox.auth.presentation; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.khu.gitbox.auth.application.AuthService; | ||
import com.khu.gitbox.auth.presentation.dto.AuthResponse; | ||
import com.khu.gitbox.auth.presentation.dto.LoginRequest; | ||
import com.khu.gitbox.common.response.ApiResponse; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
@RequiredArgsConstructor | ||
public class AuthController { | ||
|
||
private final AuthService authService; | ||
private final AuthService authService; | ||
|
||
@PostMapping("/login") | ||
public ResponseEntity<ApiResponse<AuthResponse>> login(@Valid @RequestBody LoginRequest request) { | ||
AuthResponse authResponse = authService.login(request); | ||
@PostMapping("/login") | ||
public ResponseEntity<ApiResponse<AuthResponse>> login(@Valid @RequestBody LoginRequest request) { | ||
AuthResponse authResponse = authService.login(request); | ||
|
||
// 쿠키 생성 | ||
return ResponseEntity.ok() | ||
.header("Set-Cookie", getAccessTokenHeader(authResponse.accessToken())) | ||
.body(ApiResponse.ok(authResponse)); | ||
} | ||
// 쿠키 생성 | ||
return ResponseEntity.ok() | ||
.header("Set-Cookie", getAccessTokenHeader(authResponse.accessToken())) | ||
.body(ApiResponse.ok(authResponse)); | ||
} | ||
|
||
private String getAccessTokenHeader(String accessToken) { | ||
return "accessToken=" + accessToken + "; Path=/; HttpOnly; SameSite=None; Secure"; | ||
} | ||
private String getAccessTokenHeader(String accessToken) { | ||
return "accessToken=" + accessToken + "; Path=/; HttpOnly; SameSite=None; Secure"; | ||
} | ||
} |
Oops, something went wrong.