-
Notifications
You must be signed in to change notification settings - Fork 14
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
Next 엄성민 스프린트 미션 9 #59
Open
eomsung
wants to merge
57
commits into
codeit-sprint-fullstack:main
Choose a base branch
from
eomsung:next-엄성민-9
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "next-\uC5C4\uC131\uBBFC-9"
Open
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
575a87a
chore: pr 템플릿 & 머지 후 브랜치 삭제 github action 추가
shyjnnn 13fbcd6
remove: delete github actions
shyjnnn 43c8329
feat: add: auto-labeling and assignee for PRs
shyjnnn 5b1fbb2
docs: update fe readme
sprint-edu f375c0d
Initial commit from Create Next App
eomsung f42d8be
wip
eomsung f580baf
readme update
eomsung 9ed97eb
wip
eomsung a0def70
Merge branch 'main' of https://github.com/eomsung/4-sprint-mission-fe…
eomsung 2afffe7
test
eomsung 78a9246
tst
eomsung 4620060
make freeBoard page
eomsung e96ead8
add articlepage, add comment function
eomsung c02cdf1
add button active
eomsung 520590a
add create article
eomsung 59529d3
add edit/delete function in artcle
eomsung a72aed8
add edit/delete comment function
eomsung 3d4afc3
add responsive css
eomsung 806ce0d
change baseURL
eomsung 1770d3d
edit
eomsung 4abfb8e
add cancel button in comment edit
eomsung 12d7985
wip homepage
eomsung 9c1afc7
change baseURL
eomsung d9b473f
feat: mainpage
eomsung 98196eb
add loginpage ui
eomsung 2ac74c5
refactoring : change the name freemarket to artocles
eomsung 47a340b
refactor
eomsung ad6016a
refactor
eomsung d3aea30
add windowsize hook
eomsung f0d87b2
add windowsize hook
eomsung 323c106
edit useDivicesize
eomsung f935598
edit baseurl
eomsung a920db3
add AuthContext
eomsung 7395aad
add Tokens
eomsung 732259f
add login/signup error message modal
eomsung 9717752
add visible button
eomsung 774e545
edit dropdown menu add itemdetailpage
eomsung 1289f04
add delete/edit comment function
eomsung e4f69fd
wip
eomsung 344df1c
add delete modal in product
eomsung 6cdf904
edit typo
eomsung 63b4594
edit signup and add favorite function
eomsung cb555b6
add responsive css
eomsung d1a24cc
add editPage in Product
eomsung 109a25f
add type Number in price
eomsung ddda900
refactoring
eomsung 6770243
refactoring
eomsung 5dfef77
add check login
eomsung 8d30c9b
wip
eomsung 514c0af
wip
eomsung 45adc1c
wip
eomsung 9d5b73f
edit typo
eomsung fc9f2f0
test
eomsung ee12ff9
add intercept and stale time
eomsung 884c044
add refetchInterval
eomsung 8d34b68
edti
eomsung 0322a26
edit useEffect in itemDetailpage
eomsung 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 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 |
---|---|---|
|
@@ -3,7 +3,11 @@ | |
### 기본 | ||
|
||
- [x] | ||
<<<<<<< HEAD | ||
- [테스트s] | ||
======= | ||
- [] | ||
>>>>>>> upstream/next-엄성민 | ||
- [] | ||
|
||
### 심화 | ||
|
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.* | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/versions | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.pnpm-debug.log* | ||
|
||
# env files (can opt-in for committing if needed) | ||
.env* | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
import config from "@/postcss.config.mjs"; | ||
import axios from "axios"; | ||
import { jwtDecode } from "jwt-decode"; | ||
|
||
// const baseURL = "http://localhost:3100"; | ||
const baseURL = "https://four-sprint-mission-be-1.onrender.com"; | ||
|
||
const client = axios.create({ | ||
baseURL, | ||
}); | ||
|
||
// 게시글 관련 api | ||
const getArticles = async (keyword = "", order = "recent") => { | ||
const options = { | ||
params: { | ||
keyword, | ||
orderBy: order, | ||
}, | ||
}; | ||
const url = `/article`; | ||
const response = await client.get(url, options); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const getArticle = async (id) => { | ||
const url = `/article/${id}`; | ||
const response = await client.get(url); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const createArticle = async (newArticle) => { | ||
const url = `/article`; | ||
const response = await client.post(url, newArticle); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const deleteArticle = async (id) => { | ||
const url = `/article/${id}`; | ||
const response = await client.delete(url); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const patchArticle = async (id, article) => { | ||
const url = `/article/${id}`; | ||
const response = await client.patch(url, article); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const createCommentInArticle = async (id, content) => { | ||
const url = `/article/${id}/comment`; | ||
const response = await client.post(url, { content }); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const getCommentsinArticle = async (id) => { | ||
const url = `article/${id}/comments`; | ||
const response = await client.get(url); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const deleteCommentInArticle = async (id) => { | ||
const url = `article/${id}/comment`; | ||
const response = await client.delete(url); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const patchCommentInArticle = async (id, content) => { | ||
const url = `article/${id}/comment`; | ||
const response = await client.patch(url, { content }); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
// 상품 관련 api | ||
const getProducts = async () => { | ||
const url = "/products"; | ||
const response = await client.get(url); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
// 로그인 관련 api | ||
const codeitURL = "https://panda-market-api.vercel.app"; | ||
|
||
export const codeitClient = axios.create({ | ||
baseURL: codeitURL, | ||
}); | ||
|
||
codeitClient.interceptors.request.use(async (config) => { | ||
if (config.url === "/auth/refresh-token") return config; | ||
const Authorization = config.headers.Authorization || ""; | ||
const accessToken = Authorization.split("Bearer ")[1]; | ||
|
||
if (!accessToken) return config; | ||
|
||
const { exp } = jwtDecode(accessToken); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. decode 하다가 예외가 발생 할 수 있으니 try-catch 로 한번 감싸주시는걸 권장드립니다! |
||
if (exp * 1000 >= Date.now()) return config; | ||
|
||
const prevRefreshToken = localStorage.getItem("refreshToken"); | ||
const { accessToken: newAccessToken } = await api.refreshToken( | ||
prevRefreshToken | ||
); | ||
config.headers.Authorization = `Bearer ${newAccessToken}`; | ||
|
||
return config; | ||
}); | ||
|
||
const signUp = async (dto) => { | ||
const url = "/auth/signUp"; | ||
const response = await codeitClient.post(url, dto); | ||
const data = response.data; | ||
|
||
const { accessToken, refreshToken } = data; | ||
codeitClient.defaults.headers.Authorization = `Bearer ${accessToken}`; | ||
localStorage.setItem("refreshToken", refreshToken); | ||
return data; | ||
}; | ||
|
||
const logIn = async (dto) => { | ||
const url = "/auth/signIn"; | ||
const response = await codeitClient.post(url, dto); | ||
const data = response.data; | ||
|
||
const { accessToken, refreshToken } = data; | ||
codeitClient.defaults.headers.Authorization = `Bearer ${accessToken}`; | ||
localStorage.setItem("refreshToken", refreshToken); | ||
|
||
return data; | ||
}; | ||
|
||
const refreshToken = async (prevRefreshToken) => { | ||
const url = "/auth/refresh-token"; | ||
const response = await codeitClient.post(url, { | ||
refreshToken: prevRefreshToken, | ||
}); | ||
const data = response.data; | ||
const { accessToken } = data; | ||
codeitClient.defaults.headers.Authorization = `Bearer ${accessToken}`; | ||
|
||
return data; | ||
}; | ||
|
||
// 유저정보 관련 | ||
const getUserData = async () => { | ||
const url = "/users/me"; | ||
const response = await codeitClient.get(url); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
// product | ||
const getProduct = async (productId) => { | ||
const url = `/products/${productId}`; | ||
const response = await codeitClient.get(url); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const deleteProduct = async (productId) => { | ||
const url = `/products/${productId}`; | ||
const response = await codeitClient.delete(url); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const patchProduct = async (productId, dto) => { | ||
const url = `/products/${productId}`; | ||
const response = await codeitClient.patch(url, dto); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const getCommentsInProduct = async (productId, limit = 10) => { | ||
const options = { | ||
params: { | ||
limit, | ||
}, | ||
}; | ||
const url = `/products/${productId}/comments`; | ||
const response = await codeitClient.get(url, options); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const deleteCommentInProduct = async (commentId) => { | ||
const url = `/comments/${commentId}`; | ||
const response = await codeitClient.delete(url); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const patchCommentInProduct = async (commentId, content) => { | ||
const url = `/comments/${commentId}`; | ||
const response = await codeitClient.patch(url, { content }); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const createCommentInProduct = async (productId, content) => { | ||
const url = `/products/${productId}/comments`; | ||
const response = await codeitClient.post(url, { content }); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const createFavoriteProduct = async (productId) => { | ||
const url = `/products/${productId}/favorite`; | ||
const response = await codeitClient.post(url); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const deleteFavoriteProduct = async (productId) => { | ||
const url = `/products/${productId}/favorite`; | ||
const response = await codeitClient.delete(url); | ||
const data = response.data; | ||
return data; | ||
}; | ||
|
||
const api = { | ||
getArticles, | ||
getArticle, | ||
createArticle, | ||
deleteArticle, | ||
patchArticle, | ||
createCommentInArticle, | ||
getCommentsinArticle, | ||
deleteCommentInArticle, | ||
patchCommentInArticle, | ||
getProducts, | ||
signUp, | ||
logIn, | ||
refreshToken, | ||
getUserData, | ||
getProduct, | ||
deleteProduct, | ||
patchProduct, | ||
getCommentsInProduct, | ||
deleteCommentInProduct, | ||
patchCommentInProduct, | ||
createCommentInProduct, | ||
createFavoriteProduct, | ||
deleteFavoriteProduct, | ||
}; | ||
|
||
export default api; |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use client"; | ||
|
||
import Button from "@/components/Button"; | ||
import Modal from "@/components/Modal"; | ||
import { useModal } from "@/contexts/ModalContext"; | ||
|
||
function LoginErrorModal({ children }) { | ||
const modal = useModal(); | ||
return ( | ||
<Modal> | ||
<div className="text-[18px] font-medium text-nowrap">{children}</div> | ||
<Button | ||
onClick={modal.close} | ||
className="w-[120px] h-[48px] rounded-lg py-3 px-[23px] md:w-[165px]" | ||
> | ||
확인 | ||
</Button> | ||
</Modal> | ||
); | ||
} | ||
|
||
export default LoginErrorModal; |
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.
access token 은 매번 발급받는게 아닙니다
최초 발급된 이후 localStorage 에 저장한 후에 만약 만료가 되었다면 refersh token 을 통해 다시 재발급을 해주고 활용하는 방식으로 처리하는걸 권장드립니다