-
Notifications
You must be signed in to change notification settings - Fork 18
[정성현] sprint12 #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
GANGYIKIM
merged 5 commits into
codeit-bootcamp-frontend:Next-정성현
from
jsh1147:Next-정성현-sprint12
Dec 9, 2024
The head ref may contain hidden characters: "Next-\uC815\uC131\uD604-sprint12"
Merged
[정성현] sprint12 #138
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { instance } from "./instance"; | ||
import { PATH } from "@/constants/api"; | ||
import { | ||
PostSignUpParams, | ||
PostSignUpRes, | ||
PostLogInParams, | ||
PostLogInRes, | ||
PostRefreshParams, | ||
PostRefreshRes, | ||
} from "@/types/api"; | ||
|
||
export const postSignUp = async ({ | ||
email, | ||
nickname, | ||
password, | ||
passwordConfirmation, | ||
}: PostSignUpParams) => { | ||
const bodyObj = { email, nickname, password, passwordConfirmation }; | ||
|
||
const response = await instance.post<PostSignUpRes>(PATH.SIGNUP, bodyObj); | ||
return response.data; | ||
}; | ||
|
||
export const postLogIn = async ({ email, password }: PostLogInParams) => { | ||
const bodyObj = { email, password }; | ||
|
||
const response = await instance.post<PostLogInRes>(PATH.LOGIN, bodyObj); | ||
return response.data; | ||
}; | ||
|
||
export const postRefresh = async ({ refreshToken }: PostRefreshParams) => { | ||
const bodyObj = { refreshToken }; | ||
|
||
const response = await instance.post<PostRefreshRes>(PATH.REFRESH, bodyObj); | ||
return response.data; | ||
}; |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import axios, { AxiosError } from "axios"; | ||
import { postRefresh } from "./auth"; | ||
import { BASE_URL } from "@/constants/api"; | ||
|
||
export const instance = axios.create({ | ||
baseURL: BASE_URL, | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
|
||
instance.interceptors.request.use(async (config) => { | ||
if (config.url === "auth/refresh-token") return config; | ||
|
||
try { | ||
const refresh = localStorage.getItem("refreshToken"); | ||
if (!refresh) throw new AxiosError("저장된 유저 정보가 없습니다.", "401"); | ||
|
||
const { accessToken } = await postRefresh({ refreshToken: refresh }); | ||
localStorage.setItem("accessToken", accessToken); | ||
} catch { | ||
localStorage.removeItem("accessToken"); | ||
localStorage.removeItem("refreshToken"); | ||
} | ||
|
||
const access = localStorage.getItem("accessToken"); | ||
if (access) config.headers["Authorization"] = `Bearer ${access}`; | ||
return config; | ||
}); | ||
|
||
instance.interceptors.response.use( | ||
(response) => response, | ||
(error: AxiosError<{ message: string }>) => { | ||
const res = error.response; | ||
if (res) | ||
console.log(`[${error.status}:${res.config.url}] ${res.data.message}`); | ||
|
||
return Promise.reject(error); | ||
} | ||
); |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { instance } from "./instance"; | ||
import { PATH } from "@/constants/api"; | ||
import { GetProductsParams, GetProductsRes } from "@/types/api"; | ||
|
||
export const getProducts = async ({ | ||
page = 1, | ||
pageSize = 10, | ||
orderBy = "recent", | ||
keyword, | ||
}: GetProductsParams) => { | ||
const paramObj = { page, pageSize, orderBy, ...(keyword && { keyword }) }; | ||
|
||
const response = await instance.get<GetProductsRes>(PATH.PRODUCTS, { | ||
params: paramObj, | ||
}); | ||
return response.data; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3:
타입 정의 좋습니당 👍