-
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.
- 커스텀 헤더(X-CLab-Auth)를 통해 데이터를 반환 받도록 로직 변경 - 반환 받은 데이터는 역직렬화 후 핸들링하도록 수정
- Loading branch information
Showing
4 changed files
with
53 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,60 @@ | ||
import { ServerResponse } from '@type/server'; | ||
import { END_POINTS } from '../constants/api'; | ||
import { server } from './server'; | ||
import { API_BASE_URL, END_POINTS } from '../constants/api'; | ||
|
||
interface PostLoginBody { | ||
[key: string]: string; | ||
id: string; | ||
password: string; | ||
} | ||
|
||
interface PostLoginResponse extends ServerResponse { | ||
data: string | null; | ||
} | ||
|
||
interface PostTwoFactorLoginResponse extends ServerResponse { | ||
data: { | ||
accessToken: string; | ||
refreshToken: string; | ||
}; | ||
} | ||
|
||
interface PostTwoFactorLoginBody { | ||
[key: string]: string; | ||
memberId: string; | ||
totp: string; | ||
} | ||
|
||
export const postLogin = async (body: PostLoginBody) => { | ||
const response = await server.post<PostLoginBody, PostLoginResponse>({ | ||
url: END_POINTS.LOGIN, | ||
body, | ||
const url = API_BASE_URL + END_POINTS.LOGIN; | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(body), | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
|
||
const authHeader = response.headers.get('X-Clab-Auth'); | ||
const responseBody = await response.json(); | ||
|
||
return { | ||
...response, | ||
success: responseBody.success, | ||
authHeader: authHeader, | ||
id: body.id, | ||
}; | ||
}; | ||
|
||
export const postTwoFactorLogin = async (body: PostTwoFactorLoginBody) => { | ||
return await server.post<PostTwoFactorLoginBody, PostTwoFactorLoginResponse>({ | ||
url: END_POINTS.TWO_FACTOR_LOGIN, | ||
body, | ||
const url = API_BASE_URL + END_POINTS.TWO_FACTOR_LOGIN; | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(body), | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
|
||
const authHeader = response.headers.get('X-Clab-Auth'); | ||
const responseBody = await response.json(); | ||
|
||
return { | ||
success: responseBody.success, | ||
authHeader: authHeader, | ||
}; | ||
}; |
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