Skip to content
This repository was archived by the owner on Sep 25, 2025. It is now read-only.

Commit b8f56c4

Browse files
committed
updated Backend
1 parent 081dbd6 commit b8f56c4

8 files changed

Lines changed: 225 additions & 10 deletions

File tree

backend/README.md

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
# Authentication API
2+
3+
## `POST /auth/login`
4+
5+
로그인 요청을 처리하는 엔드포인트입니다. Body에 username과 password를 포함해야 합니다.
6+
7+
```json
8+
{
9+
"username": "your_username",
10+
"password": "your_password"
11+
}
12+
```
13+
14+
성공 시 200 OK 응답과 함께 JWT 엑세스 토큰과 아이디 토큰을 반환하며, 응답 헤더에 `Set-Cookie`를 통해 JWT 리프레시 토큰을 포함합니다.
15+
16+
```json
17+
{
18+
"accessToken": "...",
19+
"idToken": "..."
20+
}
21+
```
22+
23+
```
24+
Set-Cookie: refreshToken=...; HttpOnly; Secure; SameSite=None
25+
```
26+
27+
다음과 같은 에러가 발생할 수 있습니다:
28+
29+
- `400 Bad Request: ERR_LOGIN_INVALID_CREDENTIALS`: 잘못된 아이디 또는 비밀번호입니다.
30+
- `400 Bad Request: ERR_LOGIN_USER_NOT_CONFIRMED`: 계정을 생성 후 이메일 인증을 완료하지 않았습니다.
31+
- `400 Bad Request: ERR_LOGIN_PASSWORD_RESET_REQUIRED`: 비밀번호 재설정이 필요합니다.
32+
- `400 Bad Request: ERR_LOGIN_USER_NOT_FOUND`: 해당 아이디를 가진 사용자가 없습니다.
33+
34+
## `POST /auth/signup`
35+
36+
회원가입 요청을 처리하는 엔드포인트입니다. Body에 username, password, email을 포함해야 합니다.
37+
38+
```json
39+
{
40+
"username": "your_username",
41+
"password": "your_password",
42+
"email": "your_email"
43+
}
44+
```
45+
46+
성공 시 200 OK 응답과 함께 가입 정보에 기입된 이메일로 인증 메일이 발송됩니다.
47+
48+
다음과 같은 에러가 발생할 수 있습니다:
49+
50+
- `400 Bad Request: ERR_SIGNUP_USERNAME_EXISTS`: 이미 사용 중인 아이디입니다.
51+
- `400 Bad Request: ERR_SIGNUP_INVALID_PASSWORD`: 비밀번호 조건을 만족하지 않습니다.
52+
- `400 Bad Request: ERR_SIGNUP_INVALID_PARAMETER`: 잘못된 요청 파라미터입니다.
53+
- `400 Bad Request: ERR_SIGNUP_LIMIT_EXCEEDED`: 회원가입 요청이 너무 많습니다.
54+
55+
## `POST /auth/confirmEmail`
56+
57+
이메일 인증 요청을 처리하는 엔드포인트입니다. Body에 username과 code를 포함해야 합니다. code는 이메일로 발송된 인증 코드를 입력해야 합니다.
58+
59+
```json
60+
{
61+
"username": "your_username",
62+
"code": "000000"
63+
}
64+
```
65+
66+
성공 시 200 OK 응답과 함께 인증이 완료되었다는 메시지를 반환합니다.
67+
68+
다음과 같은 에러가 발생할 수 있습니다:
69+
70+
- `400 Bad Request: ERR_CONFIRM_EMAIL_CODE_MISMATCH`: 잘못된 인증 코드입니다.
71+
- `400 Bad Request: ERR_CONFIRM_EMAIL_EXPIRED_CODE`: 인증 코드가 만료되었습니다.
72+
- `400 Bad Request: ERR_CONFIRM_EMAIL_USER_NOT_FOUND`: 해당 아이디를 가진 사용자가 없습니다.
73+
- `400 Bad Request: ERR_CONFIRM_EMAIL_ALREADY_CONFIRMED`: 이미 인증된 계정입니다.
74+
- `400 Bad Request: ERR_CONFIRM_EMAIL_TOO_MANY_ATTEMPTS`: 인증 시도가 너무 많습니다. 잠시 후 다시 시도해주세요.
75+
76+
## `POST /auth/resendEmail`
77+
78+
회원가입 시 이메일 인증을 다시 요청하는 엔드포인트입니다. Body에 username을 포함해야 합니다.
79+
80+
```json
81+
{
82+
"username": "your_username"
83+
}
84+
```
85+
86+
성공 시 200 OK 응답과 함께 인증 코드가 포함된 이메일이 다시 발송됩니다.
87+
88+
다음과 같은 에러가 발생할 수 있습니다:
89+
90+
- `400 Bad Request: ERR_RESEND_EMAIL_USER_NOT_FOUND`: 해당 아이디를 가진 사용자가 없습니다.
91+
- `400 Bad Request: ERR_RESEND_EMAIL_INVALID_PARAMETER`: 잘못된 요청 파라미터입니다.
92+
- `400 Bad Request: ERR_RESEND_EMAIL_LIMIT_EXCEEDED`: 인증 요청이 너무 많습니다.
93+
- `400 Bad Request: ERR_RESEND_EMAIL_ALREADY_CONFIRMED`: 이미 인증된 계정입니다.
94+
95+
## `POST /auth/logout`
96+
97+
로그아웃 요청을 처리하는 엔드포인트입니다. Authorization 헤더에 JWT Bearer 토큰을 포함해야 합니다.
98+
99+
성공 시 200 OK 응답과 함께 쿠키를 통해 리프레시 토큰을 삭제합니다.
100+
101+
다음과 같은 에러가 발생할 수 있습니다:
102+
- `401 Unauthorized: ERR_LOGOUT_UNAUTHORIZED`: 인증되지 않은 요청입니다.
103+
104+
## `POST /auth/refresh`
105+
106+
JWT 리프레시 토큰을 사용하여 새로운 엑세스 토큰과 아이디 토큰을 발급받는 엔드포인트입니다. 요청 헤더에 `Cookie`를 통해 리프레시 토큰을 포함해야 합니다. (`refreshToken`=...)
107+
108+
다음과 같은 에러가 발생할 수 있습니다:
109+
- `401 Unauthorized: ERR_REFRESH_UNAUTHORIZED`: 인증되지 않은 요청입니다.
110+
- `401 Unauthorized: ERR_REFRESH_INVALID_TOKEN`: 잘못된 리프레시 토큰입니다.
111+
- `401 Unauthorized: ERR_REFRESH_INVALID_PARAMETER`: 잘못된 요청 파라미터입니다.
112+
- `401 Unauthorized: ERR_REFRESH_USER_NOT_FOUND`: 해당 리프레시 토큰을 가진 사용자가 없습니다.
113+
114+
# Post CRUD API
115+
116+
## `GET /posts`
117+
118+
모든 게시글을 조회하는 엔드포인트입니다. 인증이 필요하지 않습니다.
119+
성공 시 200 OK 응답과 함께 게시글 목록을 반환합니다.
120+
121+
```json
122+
[
123+
{
124+
"userName": "...",
125+
"content": "...",
126+
"createdAt": "...",
127+
"id": "...",
128+
"userId": "...",
129+
"title": "..."
130+
},
131+
...
132+
]
133+
```
134+
135+
136+
## `GET /posts/{postId}`
137+
138+
특정 게시글을 조회하는 엔드포인트입니다. `postId`는 게시글의 고유 ID입니다. 인증이 필요하지 않습니다.
139+
140+
성공 시 200 OK 응답과 함께 게시글 정보를 반환합니다.
141+
142+
```json
143+
{
144+
"userName": "...",
145+
"content": "...",
146+
"createdAt": "...",
147+
"id": "...",
148+
"userId": "...",
149+
"title": "..."
150+
}
151+
```
152+
153+
다음과 같은 에러가 발생할 수 있습니다:
154+
- `400 Bad Request: ERR_GET_POST_BAD_REQUEST_MISSING_ID`:
155+
요청 파라미터에 게시글 ID가 없습니다.
156+
- `404 Not Found: ERR_GET_POST_NOT_FOUND`: 해당 ID를 가진 게시글이 없습니다.
157+
158+
## `POST /posts`
159+
160+
새로운 게시글을 작성하는 엔드포인트입니다. 요청 헤더에 JWT Bearer 토큰을 포함해야 하며, Body에 게시글 정보를 포함해야 합니다.
161+
162+
```json
163+
{
164+
"title": "게시글 제목",
165+
"content": "게시글 내용"
166+
}
167+
```
168+
169+
성공 시 201 Created 응답과 함께 작성된 게시글 정보를 반환합니다.
170+
(`GET /posts/{postId}`와 동일한 응답 형식)
171+
172+
다음과 같은 에러가 발생할 수 있습니다:
173+
- `400 Bad Request: ERR_CREATE_POST_BAD_REQUEST`: 요청 파라미터가 잘못되었습니다.
174+
- `401 Unauthorized: ERR_CREATE_POST_UNAUTHORIZED`: 인증되지 않은 요청입니다.
175+
176+
## `PUT /posts/{postId}`
177+
178+
게시글을 수정하는 엔드포인트입니다. `postId`는 수정할 게시글의 고유 ID이며, 요청 헤더에 JWT Bearer 토큰을 포함해야 합니다. Body에 수정할 게시글 정보를 포함해야 합니다.
179+
180+
```json
181+
{
182+
"title": "수정된 게시글 제목",
183+
"content": "수정된 게시글 내용"
184+
}
185+
```
186+
187+
성공 시 200 OK 응답과 함께 수정된 게시글 정보를 반환합니다.
188+
(`GET /posts/{postId}`와 동일한 응답 형식)
189+
190+
다음과 같은 에러가 발생할 수 있습니다:
191+
- `400 Bad Request: ERR_UPDATE_POST_BAD_REQUEST`: 요청 파라미터가 잘못되었습니다.
192+
- `400 Bad Request: ERR_UPDATE_POST_BAD_REQUEST_MISSING_ID`:
193+
요청 파라미터에 게시글 ID가 없습니다.
194+
- `401 Unauthorized: ERR_UPDATE_POST_UNAUTHORIZED`: 인증되지 않은 요청입니다.
195+
- `403 Forbidden: ERR_UPDATE_POST_FORBIDDEN`: 해당 게시글을 수정할 권한이 없습니다.
196+
- `404 Not Found: ERR_UPDATE_POST_NOT_FOUND`: 해당 ID를 가진 게시글이 없습니다.
197+
198+
## `DELETE /posts/{postId}`
199+
200+
게시글을 삭제하는 엔드포인트입니다. `postId`는 삭제할 게시글의 고유 ID이며, 요청 헤더에 JWT Bearer 토큰을 포함해야 합니다.
201+
202+
성공 시 200 OK 응답을 반환합니다.
203+
204+
다음과 같은 에러가 발생할 수 있습니다:
205+
- `400 Bad Request: ERR_DELETE_POST_BAD_REQUEST_MISSING_ID`:
206+
요청 파라미터에 게시글 ID가 없습니다.
207+
- `401 Unauthorized: ERR_DELETE_POST_UNAUTHORIZED`: 인증되지 않은 요청입니다.
208+
- `403 Forbidden: ERR_DELETE_POST_FORBIDDEN`: 해당 게시글을 삭제할 권한이 없습니다.
209+
- `404 Not Found: ERR_DELETE_POST_NOT_FOUND`: 해당 ID를 가진 게시글이 없습니다.
210+
211+
# User CRUD API
212+
213+
## `GET /users`
214+
215+
## `GET /users/{userName}`
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ export const handler = async (event: APIGatewayProxyEventV2WithJWTAuthorizer): P
99
const authHeader = event.headers.authorization || event.headers.Authorization
1010
if (!authHeader) return error(unAuthorized(), 'ERR_GET_USER_NO_AUTH_HEADER')
1111

12-
const token = authHeader.split(' ')[1] // 'Bearer xxx'
12+
const token = authHeader.split(' ')[1]
1313
if (!token) return error(unAuthorized(), 'ERR_GET_USER_NO_TOKEN')
1414

1515
const getUserCommand = new GetUserCommand({ AccessToken: token })
1616
const response = await cognitoClient.send(getUserCommand)
1717

1818
const userAttributes = Object.fromEntries(
19-
(response.UserAttributes || []).map((attr) => [attr.Name, attr.Value])
19+
(response.UserAttributes ?? []).map((attr) => [attr.Name, attr.Value])
2020
)
2121

2222
return {

backend/serverless.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,48 +91,48 @@ functions:
9191
method: post
9292

9393
acinsideSL_CreatePost:
94-
handler: dist/functions/crud/createPost.handler
94+
handler: dist/functions/post/createPost.handler
9595
events:
9696
- httpApi:
9797
path: /posts
9898
method: post
9999
authorizer: cognitoAuthorizer
100100

101101
acinsideSL_DeletePost:
102-
handler: dist/functions/crud/deletePost.handler
102+
handler: dist/functions/post/deletePost.handler
103103
events:
104104
- httpApi:
105105
path: /posts/{id}
106106
method: delete
107107
authorizer: cognitoAuthorizer
108108

109109
acinsideSL_UpdatePost:
110-
handler: dist/functions/crud/updatePost.handler
110+
handler: dist/functions/post/updatePost.handler
111111
events:
112112
- httpApi:
113113
path: /posts/{id}
114114
method: put
115115
authorizer: cognitoAuthorizer
116116

117117
acinsideSL_GetPost:
118-
handler: dist/functions/crud/getPost.handler
118+
handler: dist/functions/post/getPost.handler
119119
events:
120120
- httpApi:
121121
path: /posts/{id}
122122
method: get
123123

124124
acinsideSL_GetPosts:
125-
handler: dist/functions/crud/getPosts.handler
125+
handler: dist/functions/post/getPosts.handler
126126
events:
127127
- httpApi:
128128
path: /posts
129129
method: get
130130

131-
acinsideSL_GetUser:
132-
handler: dist/functions/user/getUserInfo.handler
131+
acinsideSL_MyInfo:
132+
handler: dist/functions/user/myInfo.handler
133133
events:
134134
- httpApi:
135-
path: /getuserinfo
135+
path: /myinfo
136136
method: get
137137
authorizer: cognitoAuthorizer
138138

0 commit comments

Comments
 (0)