-
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.
* chore: 커밋용 next/core-web-vitals삭제 * feat: 회원가입 및 카카오 로그인 후 토큰 저장 * chore: 프로필 이미지 s3 * fix: 인터셉트 엑세스 토큰 * fix: 기존 계정 홈, 새로운 계정 프로필 수정으로 변경 및 토큰 저장 * fix: 404 에러시 data.data에 null 설정 * feat: 받아온 재료 404 에러 시 데이터 전달 조건 추가 * feat: 401 에러시 리프레시 토큰 api 요청 로직 추가 * feat: 홈페이지 로컬스토리지 토큰 없을 시 로그인 페이지 이동 * fix: 커밋 'next/core-web-vitals' 되돌리기
- Loading branch information
Showing
16 changed files
with
235 additions
and
82 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
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
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
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 +1,2 @@ | ||
export { default as useGetKakaoToken } from './useGetKakaoToken'; | ||
export { default as usePostUser } from './usePostUser'; |
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,35 @@ | ||
import { useRouter } from 'next/router'; | ||
import { queryKeys } from '../queryKeys'; | ||
import { useBaseMutation } from '../useBaseMutation'; | ||
|
||
interface PostUserBodyType { | ||
nickName: string; | ||
kakaoId: number; | ||
kakaoEmail: string; | ||
googleEmail: string; | ||
profileImage: string; | ||
} | ||
|
||
const usePostUser = () => { | ||
const router = useRouter(); | ||
const onSuccess = ({ | ||
data, | ||
}: { | ||
data: { | ||
accessToken: string; | ||
refreshToken: string; | ||
email: string; | ||
nickName: string; | ||
}; | ||
}) => { | ||
localStorage.setItem('accessToken', data.accessToken); | ||
localStorage.setItem('refreshToken', data.refreshToken); | ||
void router.push('/home'); | ||
}; | ||
return useBaseMutation<PostUserBodyType>( | ||
queryKeys.KAKAO(), | ||
`/users`, | ||
onSuccess, | ||
); | ||
}; | ||
export default usePostUser; |
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 @@ | ||
import axiosInstance from '@/api/axiosInstance'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
export const fetchData = async <T>(url: string, body: T) => { | ||
const response = await axiosInstance.post<{ data: T }>(url, body); | ||
return response.data; | ||
}; | ||
|
||
export const useBaseMutation = <T>( | ||
mutationKey: any, | ||
url: string, | ||
onSuccess: (any: any) => void, | ||
) => { | ||
return useMutation({ | ||
mutationKey, | ||
mutationFn: async (body: T) => { | ||
const response = await fetchData<T>(url, body); | ||
|
||
onSuccess(response.data); | ||
}, | ||
}); | ||
}; |
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,14 +1,29 @@ | ||
import axiosInstance from '@/api/axiosInstance'; | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
|
||
export const fetchData = async <T>(url: string) => { | ||
const response = await axiosInstance.get<{ data: T }>(url); | ||
return response.data; | ||
export const fetchData = async <T>(url: string, isNotCatch: boolean) => { | ||
try { | ||
const response = await axiosInstance.get<{ data: T; status?: number }>(url); | ||
return response.data; | ||
} catch (error: any) { | ||
if (!isNotCatch) { | ||
if (error.response && error.response.status === 404) { | ||
return await Promise.resolve({ data: null }); | ||
} else { | ||
throw error; | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export const useBaseQuery = <T>(queryKey: any, url: string) => { | ||
export const useBaseQuery = <T>( | ||
queryKey: any, | ||
url: string, | ||
isNotCatch: boolean = false, | ||
) => { | ||
return useSuspenseQuery({ | ||
queryKey, | ||
queryFn: async () => await fetchData<T>(url).then((res) => res.data), | ||
queryFn: async () => { | ||
return await fetchData<T>(url, isNotCatch); | ||
}, | ||
}); | ||
}; |
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
Oops, something went wrong.