codestates / codestates/BanThing

[Error Handling] cookie 전달 에러

Open
#152 0 comments 0 reactions 1 assignee Claimed by @minho0513 View on GitHub
error server solved
Dominant language
TypeScript
Stars
0
Forks
2
PR merge metrics
No merged PRs in 30d

Description

### 어떤 에러인가요?
- postman 에서는 쿠키가 전달되는게 확인됐지만
![스크린샷 2022-02-23 오후 1 12 03](https://user-images.githubusercontent.com/91890435/155260688-f7e0120a-a09e-4d62-834e-86474274b64c.png)

브라우저 상에서 쿠키가 전달되지 않습니다.
![스크린샷 2022-02-23 오후 1 12 25](https://user-images.githubusercontent.com/91890435/155260702-f8f48c9b-b38d-4887-bd05-b1c39b66445f.png)

![스크린샷 2022-02-24 오후 4 05 05](https://user-images.githubusercontent.com/91890435/155475114-4ca30ea9-0ea4-4156-a3ed-90584639d0f1.png)

### 에러 핸들링 방법
- axios요청 보낼때 { withCredentials: true } 를 추가해주었습니다.
- 그리고 서버코드는 cors origin 을 "*" -> localhost 로 변경해줬습니다.
```
//Client
axios
.post(
`${process.env.NEXT_PUBLIC_SERVER_ENDPOINT}/users/login`,
{
user_id: userId,
password: password,
},
{ withCredentials: true },
)

//Server
app.enableCors({
origin: ['http://localhost:3000'],
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
credentials: true,
});
```

### 에러 핸들링을 위해 참고한 레퍼런스 링크

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.