-
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: 로그인 이미지 추가 * feat: 로그인 페이지 마크업 추가 * chore: 환경변수 .gitignore 추가 * feat: 카카오 로그인 코드 받아오기 * feat: 로그인 페이지 이동 HOC * feat: 구글 로그인 URL 추가 * feat: 전역 QueryClientProvider 추가 * feat: 카카오 로그인 api 요청 Network Error * feat: 식자재 불러오기 api 추가 Network Error * fix: 쿼리 키 분리 * feat: 기본 useBaseQuery 추가 * chore: 프로필 경고메시지 atom 분리 * chore: 워크플로우 환경변수 추가
- Loading branch information
Showing
21 changed files
with
322 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ yarn-error.log* | |
|
||
# local env files | ||
.env*.local | ||
.env | ||
|
||
# vercel | ||
.vercel | ||
|
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,31 @@ | ||
import axiosInstance from '../axiosInstance'; | ||
|
||
interface LoginResponseType { | ||
data: { accessToken: string; refreshToken: string; email: string }; | ||
} | ||
|
||
const fetchKaKao = async (code: string): Promise<LoginResponseType> => | ||
await axiosInstance.get(`/users/kakao-login?code=${code}`); | ||
|
||
export const getKaKaoToken: (code: string) => Promise<void> = async (code) => { | ||
fetchKaKao(code) | ||
.then((response: LoginResponseType) => { | ||
localStorage.setItem('token', response.data.accessToken); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); | ||
}; | ||
|
||
const fetchGoogle = async (code: string): Promise<LoginResponseType> => | ||
await axiosInstance.get(`/users/google-login?code=${code}`); | ||
|
||
export const getGoogleToken: (code: string) => Promise<void> = async (code) => { | ||
fetchGoogle(code) | ||
.then((response: LoginResponseType) => { | ||
localStorage.setItem('token', response.data.accessToken); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,23 @@ | ||
import React from 'react'; | ||
import { ExclamationIcon } from '@/assets/icons'; | ||
|
||
interface AlertMessageProps { | ||
message: string; | ||
className?: string; | ||
} | ||
|
||
const ExclamationAlertSpan: React.FC<AlertMessageProps> = ({ | ||
message, | ||
className, | ||
}) => { | ||
return ( | ||
<span | ||
className={`flex items-center gap-[4px] text-point4 body1-medium ${className}`} | ||
> | ||
<ExclamationIcon /> | ||
{message} | ||
</span> | ||
); | ||
}; | ||
|
||
export default ExclamationAlertSpan; |
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,28 @@ | ||
import React, { useEffect } from 'react'; | ||
import { useRouter } from 'next/router'; | ||
|
||
const withLogin = (InnerComponent: React.FC) => { | ||
return () => { | ||
const router = useRouter(); | ||
const token = localStorage.getItem('token'); | ||
|
||
const redirectToLogin: () => Promise<void> = async () => { | ||
if (!token) { | ||
alert('로그인이 필요합니다.'); | ||
try { | ||
await router.push('/login'); | ||
} catch (error) { | ||
console.error('로그인 체크 에러', error); | ||
} | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
void redirectToLogin(); | ||
}, [token]); | ||
|
||
return token ? <InnerComponent /> : null; | ||
}; | ||
}; | ||
|
||
export default withLogin; |
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 @@ | ||
export { default as useGetIngredientList } from './useGetIngredientList'; |
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,9 @@ | ||
import type { IngredientType } from '@/types/fridge'; | ||
import { queryKeys } from '../queryKeys'; | ||
import { useBaseQuery } from '../useBaseQuery'; | ||
|
||
const useGetIngredientList = () => { | ||
return useBaseQuery<IngredientType>(queryKeys.INGREDIENT(), '/ingrs'); | ||
}; | ||
|
||
export default useGetIngredientList; |
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,5 @@ | ||
export const queryKeys = { | ||
INGREDIENT: (id?: number) => ['ingredient', id] as const, | ||
} as const; | ||
|
||
export type QueryKeys = (typeof queryKeys)[keyof typeof queryKeys]; |
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,19 @@ | ||
import axiosInstance from '@/api/axiosInstance'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
export const fetchData = async <T>(url: string) => { | ||
const response = await axiosInstance.get<{ data: T }>(url); | ||
return response.data; | ||
}; | ||
|
||
export const useBaseQuery = <T>(queryKey: any, url: string) => { | ||
return useQuery({ | ||
queryKey, | ||
queryFn: async () => | ||
await fetchData<T>(url) | ||
.then((res) => res.data) | ||
.catch((error) => { | ||
console.error(error); | ||
}), | ||
}); | ||
}; |
Oops, something went wrong.