Skip to content

Commit

Permalink
fix: CORS 에러 수정
Browse files Browse the repository at this point in the history
- NGINX 요청 시 CORS 에러를 수정
  • Loading branch information
JoonSoo-Kim committed Dec 7, 2023
1 parent 952ce9a commit a445f95
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
21 changes: 15 additions & 6 deletions BE/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Get,
HttpCode,
Post,
Redirect,
Req,
UseGuards,
} from "@nestjs/common";
Expand All @@ -26,22 +27,30 @@ export class AuthController {

@Get("/kakao/callback")
@UseGuards(AuthGuard("kakao"))
@HttpCode(201)
@Redirect(process.env.FRONTEND_URL, 302)
async kakaoSignIn(
@GetUser() user: User,
@Req() request: Request,
): Promise<LoginResponseDto> {
return await this.authService.kakaoSignIn(user, request);
): Promise<object> {
const loginResponseDto: LoginResponseDto =
await this.authService.kakaoSignIn(user, request);
return {
url: `${process.env.FRONTEND_URL}?access-token=${loginResponseDto.accessToken}&nickname=${loginResponseDto.nickname}&premium=${loginResponseDto.premium}`,
};
}

@Get("/naver/callback")
@UseGuards(AuthGuard("naver"))
@HttpCode(201)
@Redirect(process.env.FRONTEND_URL, 302)
async naverSignIn(
@GetUser() user: User,
@Req() request: Request,
): Promise<LoginResponseDto> {
return await this.authService.naverSignIn(user, request);
): Promise<object> {
const loginResponseDto: LoginResponseDto =
await this.authService.naverSignIn(user, request);
return {
url: `${process.env.FRONTEND_URL}?access-token=${loginResponseDto.accessToken}&nickname=${loginResponseDto.nickname}&premium=${loginResponseDto.premium}`,
};
}

@Post("/signup")
Expand Down
14 changes: 14 additions & 0 deletions FE/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ function App() {
}, []);

useEffect(() => {
if (window.location.search) {
const params = new URLSearchParams(window.location.search);

const accessToken = params.get("access-token");
const nickname = params.get("nickname");

if (accessToken && nickname) {
setUserState({ ...userState, isLogin: true, accessToken, nickname });
sessionStorage.setItem("accessToken", accessToken);
sessionStorage.setItem("nickname", nickname);
window.history.replaceState({}, "", "/");
}
}

window.onpopstate = (event) => {
if (event.state) {
setDiaryState(event.state);
Expand Down

0 comments on commit a445f95

Please sign in to comment.