-
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.
feat: add api base code (incomplete)
- Loading branch information
Showing
33 changed files
with
931 additions
and
452 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Api } from '@server'; | ||
|
||
export const api_loginWithKakao = new Api< | ||
{ code: string; state: string }, | ||
{ | ||
userId: number; | ||
accessToken: string; | ||
accessTokenExpiresAt: string; | ||
refreshToken: string; | ||
refreshTokenExpiresAt: string; | ||
} | ||
>({ | ||
method: 'POST', | ||
endpoint: '/login/oauth2/code/kakao', | ||
needToLogin: false, | ||
request: (variables) => ({ | ||
queryParams: { | ||
code: variables.code, | ||
state: variables.state, | ||
}, | ||
}), | ||
}); |
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,4 +1,4 @@ | ||
import { createContext } from 'react'; | ||
import { type ClientEnv } from '@server/constants/env'; | ||
import { type ClientEnv } from '@server'; | ||
|
||
export const EnvContext = createContext<ClientEnv | null>(null); |
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,16 @@ | ||
import { create } from 'zustand'; | ||
import { type FrontendErrorResponse } from '@server'; | ||
|
||
interface ErrorToastStore { | ||
error: FrontendErrorResponse<unknown> | null; | ||
setError: (newError: FrontendErrorResponse<unknown>) => void; | ||
clearError: () => void; | ||
} | ||
|
||
const useErrorToast = create<ErrorToastStore>()((set) => ({ | ||
error: null, | ||
setError: (newError) => set({ error: newError }), | ||
clearError: () => set({ error: null }), | ||
})); | ||
|
||
export default useErrorToast; |
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,37 @@ | ||
import { type TypedResponse } from '@remix-run/cloudflare'; | ||
// `useTypedFetcher`를 사용하라는 규칙인데 이 파일이 바로 그 구현체이므로 무시 | ||
// eslint-disable-next-line no-restricted-imports | ||
import { useFetcher } from '@remix-run/react'; | ||
import { useEffect } from 'react'; | ||
import useErrorToast from './useErrorToast'; | ||
import { | ||
type FrontendErrorResponse, | ||
type FrontendSuccessResponse, | ||
type JsonValue, | ||
} from '@server'; | ||
|
||
const useTypedFetcher = < | ||
T extends ( | ||
...params: unknown[] | ||
) => Promise< | ||
| TypedResponse<FrontendSuccessResponse<JsonValue>> | ||
| TypedResponse<FrontendErrorResponse<JsonValue>> | ||
>, | ||
>( | ||
...params: Parameters<typeof useFetcher<T>> | ||
) => { | ||
const fetcher = useFetcher<T>(...params); | ||
const { setError } = useErrorToast(); | ||
|
||
useEffect(() => { | ||
if (fetcher.data !== undefined && !fetcher.data.isSuccess) { | ||
setError(fetcher.data); | ||
} | ||
// `fetcher.data` 외 다른 것이 변할 때는 실행되면 안 됨 | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [fetcher.data]); | ||
|
||
return fetcher; | ||
}; | ||
|
||
export default useTypedFetcher; |
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,15 +1,23 @@ | ||
import { type LoaderFunctionArgs } from '@remix-run/cloudflare'; | ||
|
||
export const loader = async ({ request }: LoaderFunctionArgs) => { | ||
const url = new URL(request.url); | ||
const code = url.searchParams.get('code'); | ||
const state = url.searchParams.get('state'); | ||
|
||
console.log(code, state); | ||
const cookieHeader = request.headers; | ||
console.log(cookieHeader); | ||
|
||
return null; | ||
}; | ||
|
||
const KakaoRedirect = () => <div>카카오 로그인 중...</div>; | ||
const KakaoRedirect = () => { | ||
console.log('kakaoredirect'); | ||
|
||
return ( | ||
<div> | ||
{/* <p className={textStyle.headline1B}>{fetcher.state}</p> | ||
<fetcher.Form method="POST"> | ||
<button type="submit">test submit</button> | ||
</fetcher.Form> */} | ||
</div> | ||
); | ||
}; | ||
|
||
export default KakaoRedirect; |
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.