From dfab0481b8b30d23ba50083918fb7db7d2e5e81e Mon Sep 17 00:00:00 2001 From: oaoong Date: Fri, 3 Nov 2023 01:17:20 +0900 Subject: [PATCH 1/6] =?UTF-8?q?:tada:=20validate=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 ++ pnpm-lock.yaml | 15 +++++++++++++++ src/config/apiEndPoint.ts | 1 + src/config/environment.ts | 7 +++++++ src/services/auth/auth.ts | 16 +++++++++++++++- 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 52932ff0..a0e31c71 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "classnames": "^2.3.2", "clsx": "^2.0.0", "date-fns": "^2.30.0", + "js-cookie": "^3.0.5", "next": "13.5.6", "next-themes": "^0.2.1", "react": "^18", @@ -52,6 +53,7 @@ "@storybook/theming": "^7.5.1", "@tanstack/eslint-plugin-query": "^5.0.0", "@trivago/prettier-plugin-sort-imports": "^4.2.0", + "@types/js-cookie": "^3.0.5", "@types/node": "^20", "@types/react": "^18.2.33", "@types/react-dom": "^18", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b3e03dcb..a7eb0531 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -47,6 +47,9 @@ dependencies: date-fns: specifier: ^2.30.0 version: 2.30.0 + js-cookie: + specifier: ^3.0.5 + version: 3.0.5 next: specifier: 13.5.6 version: 13.5.6(@babel/core@7.23.2)(react-dom@18.0.0)(react@18.0.0) @@ -115,6 +118,9 @@ devDependencies: '@trivago/prettier-plugin-sort-imports': specifier: ^4.2.0 version: 4.2.0(prettier@3.0.3) + '@types/js-cookie': + specifier: ^3.0.5 + version: 3.0.5 '@types/node': specifier: ^20 version: 20.0.0 @@ -4800,6 +4806,10 @@ packages: '@types/istanbul-lib-report': 3.0.2 dev: true + /@types/js-cookie@3.0.5: + resolution: {integrity: sha512-dtLshqoiGRDHbHueIT9sjkd2F4tW1qPSX2xKAQK8p1e6pM+Z913GM1shv7dOqqasEMYbC5zEaClJomQe8OtQLA==} + dev: true + /@types/js-levenshtein@1.1.2: resolution: {integrity: sha512-/NCbMABw2uacuyE16Iwka1EzREDD50/W2ggRBad0y1WHBvAkvR9OEINxModVY7D428gXBe0igeVX7bUc9GaslQ==} dev: true @@ -8845,6 +8855,11 @@ packages: resolution: {integrity: sha512-gFqAIbuKyyso/3G2qhiO2OM6shY6EPP/R0+mkDbyspxKazh8BXDC5FiFsUjlczgdNz/vfra0da2y+aHrusLG/Q==} hasBin: true + /js-cookie@3.0.5: + resolution: {integrity: sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==} + engines: {node: '>=14'} + dev: false + /js-levenshtein@1.1.6: resolution: {integrity: sha512-X2BB11YZtrRqY4EnQcLX5Rh373zbK4alC1FW7D7MBhL2gtcC17cTnr6DmfHZeS0s2rTHjUTMMHfG7gO8SSdw+g==} engines: {node: '>=0.10.0'} diff --git a/src/config/apiEndPoint.ts b/src/config/apiEndPoint.ts index d7cc5532..76a7383c 100644 --- a/src/config/apiEndPoint.ts +++ b/src/config/apiEndPoint.ts @@ -1,6 +1,7 @@ const ApiEndPoint = { kakaoLogin: () => '/oauth2/authorize/kakao/login', googleLogin: () => '/oauth2/authorize/google/login', + getValidateUser: () => '/users', test: () => '/test', } as const diff --git a/src/config/environment.ts b/src/config/environment.ts index 51aef80b..14efb89c 100644 --- a/src/config/environment.ts +++ b/src/config/environment.ts @@ -1,3 +1,5 @@ +import { assertValue } from '@/utils' + export const Environment = { apiAddress: () => process.env.NEXT_PUBLIC_API_MOCKING === 'enabled' @@ -5,4 +7,9 @@ export const Environment = { : process.env.NEXT_PUBLIC_API_ADDRESS, apiMocking: () => process.env.NEXT_PUBLIC_API_MOCKING === 'enabled' ? 'enabled' : 'disabled', + tokenName: () => assertEnv('NEXT_PUBLIC_API_TOKEN_NAME'), +} + +function assertEnv(key: string) { + return assertValue(process.env[key], `${key}가 설정되지 않았습니다.`) } diff --git a/src/services/auth/auth.ts b/src/services/auth/auth.ts index 201db899..35dcd337 100644 --- a/src/services/auth/auth.ts +++ b/src/services/auth/auth.ts @@ -1,4 +1,6 @@ +import Cookies from 'js-cookie' import ApiEndPoint from '@/config/apiEndPoint' +import { Environment } from '@/config/environment' import apiClient from '../apiClient' const getKakaoLogin = async () => { @@ -13,4 +15,16 @@ const getGoogleLogin = async () => { return response } -export { getKakaoLogin, getGoogleLogin } +const getValidateUser = async () => { + const token = Cookies.get(Environment.tokenName()) + const response = await apiClient.get( + ApiEndPoint.getValidateUser(), + {}, + { + Authorization: `Bearer ${token}`, + }, + ) + return response +} + +export { getKakaoLogin, getGoogleLogin, getValidateUser } From 7a7c8329ad99e21d96a4a898bd93a54680803e60 Mon Sep 17 00:00:00 2001 From: oaoong Date: Fri, 3 Nov 2023 01:46:58 +0900 Subject: [PATCH 2/6] =?UTF-8?q?:tada:=20auth=20provider=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/layout.tsx | 17 +++++++++------- src/config/environment.ts | 8 ++------ src/contexts/AuthProvider.tsx | 36 ++++++++++++++++++++++++++++++++++ src/hooks/useValidate.ts | 37 +++++++++++++++++++++++++++++++++++ src/services/auth/auth.ts | 5 +---- 5 files changed, 86 insertions(+), 17 deletions(-) create mode 100644 src/contexts/AuthProvider.tsx create mode 100644 src/hooks/useValidate.ts diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 6f9dd813..de39c683 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -2,6 +2,7 @@ import { Suspense } from 'react' import type { Metadata } from 'next' import Header from '@/components/domain/Header' import { Environment } from '@/config/environment' +import AuthProvider from '@/contexts/AuthProvider' import MSWWrapper from '@/contexts/MSWWrapper' import TanstackQueryContext from '@/contexts/TanstackQueryContext' import ThemeProviderContext from '@/contexts/ThemeProviderContext' @@ -32,13 +33,15 @@ export default function RootLayout({ - loading...}> -
-
- {children} - {authModal} -
-
+ + loading...}> +
+
+ {children} + {authModal} +
+
+
diff --git a/src/config/environment.ts b/src/config/environment.ts index 14efb89c..85c87900 100644 --- a/src/config/environment.ts +++ b/src/config/environment.ts @@ -1,4 +1,4 @@ -import { assertValue } from '@/utils' +// import { assertValue } from '@/utils' export const Environment = { apiAddress: () => @@ -7,9 +7,5 @@ export const Environment = { : process.env.NEXT_PUBLIC_API_ADDRESS, apiMocking: () => process.env.NEXT_PUBLIC_API_MOCKING === 'enabled' ? 'enabled' : 'disabled', - tokenName: () => assertEnv('NEXT_PUBLIC_API_TOKEN_NAME'), -} - -function assertEnv(key: string) { - return assertValue(process.env[key], `${key}가 설정되지 않았습니다.`) + tokenName: () => process.env.NEXT_PUBLIC_API_TOKEN_NAME ?? '', } diff --git a/src/contexts/AuthProvider.tsx b/src/contexts/AuthProvider.tsx new file mode 100644 index 00000000..e43a2f2f --- /dev/null +++ b/src/contexts/AuthProvider.tsx @@ -0,0 +1,36 @@ +'use client' + +import React, { createContext, useMemo } from 'react' +import useValidate from '@/hooks/useValidate' + +const AuthContext = createContext<{ + currentUser: any + isLoggedIn: boolean +}>({ + currentUser: null, + isLoggedIn: false, +}) + +const AuthProvider = ({ children }: { children: React.ReactNode }) => { + const { isLoggedIn, currentUser } = useValidate() + + const contextValue = useMemo( + () => ({ isLoggedIn, currentUser }), + [isLoggedIn, currentUser], + ) + + return ( + {children} + ) +} + +const useAuth = () => { + const context = React.useContext(AuthContext) + if (context === undefined) { + throw new Error(`useAuth must be used within a AuthProvider`) + } + return context +} + +export default AuthProvider +export { useAuth } diff --git a/src/hooks/useValidate.ts b/src/hooks/useValidate.ts new file mode 100644 index 00000000..463e7475 --- /dev/null +++ b/src/hooks/useValidate.ts @@ -0,0 +1,37 @@ +import { useEffect, useState } from 'react' +import { useQuery } from '@tanstack/react-query' +import Cookies from 'js-cookie' +import { usePathname } from 'next/navigation' +import { Environment } from '@/config/environment' +import { getValidateUser } from '@/services/auth/auth' + +const useValidate = () => { + const token = Cookies.get(Environment.tokenName()) + const pathname = usePathname() + + const [isLoggedIn, setIsLoggedIn] = useState(!!token) + const [currentUser, setCurrentUser] = useState(undefined) + + const { data, isError } = useQuery({ + queryKey: ['validate', token], + queryFn: async () => await getValidateUser(token), + enabled: !!token, + }) + + useEffect(() => { + if (isError) { + Cookies.remove(Environment.tokenName()) + setIsLoggedIn(() => false) + setCurrentUser(() => undefined) + } + if (data) { + setIsLoggedIn(() => true) + setCurrentUser(() => data.data) + } + console.log('validate', isLoggedIn, currentUser) + }, [data, isError, pathname, token]) + + return { isLoggedIn, currentUser } +} + +export default useValidate diff --git a/src/services/auth/auth.ts b/src/services/auth/auth.ts index 35dcd337..5e97d4a6 100644 --- a/src/services/auth/auth.ts +++ b/src/services/auth/auth.ts @@ -1,6 +1,4 @@ -import Cookies from 'js-cookie' import ApiEndPoint from '@/config/apiEndPoint' -import { Environment } from '@/config/environment' import apiClient from '../apiClient' const getKakaoLogin = async () => { @@ -15,8 +13,7 @@ const getGoogleLogin = async () => { return response } -const getValidateUser = async () => { - const token = Cookies.get(Environment.tokenName()) +const getValidateUser = async (token: string | undefined) => { const response = await apiClient.get( ApiEndPoint.getValidateUser(), {}, From 4f19f4f646300475336fb73c6a8abb76c19578e4 Mon Sep 17 00:00:00 2001 From: oaoong Date: Fri, 3 Nov 2023 02:00:10 +0900 Subject: [PATCH 3/6] =?UTF-8?q?:tada:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=8B=9C=20=ED=86=A0=ED=81=B0=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/domain/LoginForm/LoginForm.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/domain/LoginForm/LoginForm.tsx b/src/components/domain/LoginForm/LoginForm.tsx index b8e6aa44..6aaf3bfe 100644 --- a/src/components/domain/LoginForm/LoginForm.tsx +++ b/src/components/domain/LoginForm/LoginForm.tsx @@ -1,9 +1,11 @@ 'use client' +import Cookies from 'js-cookie' import Image from 'next/image' import { useRouter } from 'next/navigation' import AppPath from '@/config/appPath' import Assets from '@/config/assets' +import { Environment } from '@/config/environment' import { getGoogleLogin, getKakaoLogin } from '@/services/auth/auth' import LoginButtons from './section/LoginButtons' @@ -15,6 +17,7 @@ const LoginForm = () => { const res = await getKakaoLogin() const data = await res.json() console.log(data) + Cookies.set(Environment.tokenName(), data?.data?.token?.accessToken) alert('로그인 성공') router.back() } catch (e) { @@ -29,6 +32,7 @@ const LoginForm = () => { const res = await getGoogleLogin() const data = await res.json() console.log(data) + Cookies.set(Environment.tokenName(), data?.data?.token?.accessToken) alert('로그인 성공') router.back() } catch (e) { From f7aaba8aa89035d5950d59c0d92edad8affdec26 Mon Sep 17 00:00:00 2001 From: oaoong Date: Fri, 3 Nov 2023 15:51:51 +0900 Subject: [PATCH 4/6] =?UTF-8?q?:tada:=20auth=20provider=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- pnpm-lock.yaml | 150 +++++++++--------- src/app/layout.tsx | 37 +++-- src/components/domain/Header/Header.tsx | 58 ++----- .../domain/Header/section/Avatar.tsx | 57 +++++++ src/components/domain/LoginForm/LoginForm.tsx | 3 +- src/config/environment.ts | 6 +- src/contexts/AuthProvider.tsx | 4 +- src/hooks/useValidate.ts | 12 +- src/lib/fetchAPI.tsx | 4 +- src/lib/msw/mocks/authHandlers.ts | 27 ++++ src/services/apiClient.ts | 3 - 12 files changed, 213 insertions(+), 150 deletions(-) create mode 100644 src/components/domain/Header/section/Avatar.tsx diff --git a/package.json b/package.json index a0e31c71..c428c7b0 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "clsx": "^2.0.0", "date-fns": "^2.30.0", "js-cookie": "^3.0.5", - "next": "13.5.6", + "next": "14.0.1", "next-themes": "^0.2.1", "react": "^18", "react-dom": "^18", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a7eb0531..abd540e4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,11 +51,11 @@ dependencies: specifier: ^3.0.5 version: 3.0.5 next: - specifier: 13.5.6 - version: 13.5.6(@babel/core@7.23.2)(react-dom@18.0.0)(react@18.0.0) + specifier: 14.0.1 + version: 14.0.1(@babel/core@7.23.2)(react-dom@18.0.0)(react@18.0.0) next-themes: specifier: ^0.2.1 - version: 0.2.1(next@13.5.6)(react-dom@18.0.0)(react@18.0.0) + version: 0.2.1(next@14.0.1)(react-dom@18.0.0)(react@18.0.0) react: specifier: ^18 version: 18.0.0 @@ -102,7 +102,7 @@ devDependencies: version: 7.5.0(@types/react-dom@18.0.0)(@types/react@18.2.33)(react-dom@18.0.0)(react@18.0.0) '@storybook/nextjs': specifier: 7.5.0 - version: 7.5.0(@swc/core@1.3.95)(@types/react-dom@18.0.0)(@types/react@18.2.33)(esbuild@0.18.20)(next@13.5.6)(react-dom@18.0.0)(react@18.0.0)(typescript@5.2.2)(webpack@5.89.0) + version: 7.5.0(@swc/core@1.3.95)(@types/react-dom@18.0.0)(@types/react@18.2.33)(esbuild@0.18.20)(next@14.0.1)(react-dom@18.0.0)(react@18.0.0)(typescript@5.2.2)(webpack@5.89.0) '@storybook/react': specifier: 7.5.0 version: 7.5.0(react-dom@18.0.0)(react@18.0.0)(typescript@5.2.2) @@ -2036,8 +2036,8 @@ packages: tar-fs: 2.1.1 dev: true - /@next/env@13.5.6: - resolution: {integrity: sha512-Yac/bV5sBGkkEXmAX5FWPS9Mmo2rthrOPRQQNfycJPkjUAUclomCPH7QFVCDQ4Mp2k2K1SSM6m0zrxYrOwtFQw==} + /@next/env@14.0.1: + resolution: {integrity: sha512-Ms8ZswqY65/YfcjrlcIwMPD7Rg/dVjdLapMcSHG26W6O67EJDF435ShW4H4LXi1xKO1oRc97tLXUpx8jpLe86A==} /@next/eslint-plugin-next@13.5.6: resolution: {integrity: sha512-ng7pU/DDsxPgT6ZPvuprxrkeew3XaRf4LAT4FabaEO/hAbvVx4P7wqnqdbTdDn1kgTvsI4tpIgT4Awn/m0bGbg==} @@ -2045,72 +2045,72 @@ packages: glob: 7.1.7 dev: true - /@next/swc-darwin-arm64@13.5.6: - resolution: {integrity: sha512-5nvXMzKtZfvcu4BhtV0KH1oGv4XEW+B+jOfmBdpFI3C7FrB/MfujRpWYSBBO64+qbW8pkZiSyQv9eiwnn5VIQA==} + /@next/swc-darwin-arm64@14.0.1: + resolution: {integrity: sha512-JyxnGCS4qT67hdOKQ0CkgFTp+PXub5W1wsGvIq98TNbF3YEIN7iDekYhYsZzc8Ov0pWEsghQt+tANdidITCLaw==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] requiresBuild: true optional: true - /@next/swc-darwin-x64@13.5.6: - resolution: {integrity: sha512-6cgBfxg98oOCSr4BckWjLLgiVwlL3vlLj8hXg2b+nDgm4bC/qVXXLfpLB9FHdoDu4057hzywbxKvmYGmi7yUzA==} + /@next/swc-darwin-x64@14.0.1: + resolution: {integrity: sha512-625Z7bb5AyIzswF9hvfZWa+HTwFZw+Jn3lOBNZB87lUS0iuCYDHqk3ujuHCkiyPtSC0xFBtYDLcrZ11mF/ap3w==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] requiresBuild: true optional: true - /@next/swc-linux-arm64-gnu@13.5.6: - resolution: {integrity: sha512-txagBbj1e1w47YQjcKgSU4rRVQ7uF29YpnlHV5xuVUsgCUf2FmyfJ3CPjZUvpIeXCJAoMCFAoGnbtX86BK7+sg==} + /@next/swc-linux-arm64-gnu@14.0.1: + resolution: {integrity: sha512-iVpn3KG3DprFXzVHM09kvb//4CNNXBQ9NB/pTm8LO+vnnnaObnzFdS5KM+w1okwa32xH0g8EvZIhoB3fI3mS1g==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] requiresBuild: true optional: true - /@next/swc-linux-arm64-musl@13.5.6: - resolution: {integrity: sha512-cGd+H8amifT86ZldVJtAKDxUqeFyLWW+v2NlBULnLAdWsiuuN8TuhVBt8ZNpCqcAuoruoSWynvMWixTFcroq+Q==} + /@next/swc-linux-arm64-musl@14.0.1: + resolution: {integrity: sha512-mVsGyMxTLWZXyD5sen6kGOTYVOO67lZjLApIj/JsTEEohDDt1im2nkspzfV5MvhfS7diDw6Rp/xvAQaWZTv1Ww==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] requiresBuild: true optional: true - /@next/swc-linux-x64-gnu@13.5.6: - resolution: {integrity: sha512-Mc2b4xiIWKXIhBy2NBTwOxGD3nHLmq4keFk+d4/WL5fMsB8XdJRdtUlL87SqVCTSaf1BRuQQf1HvXZcy+rq3Nw==} + /@next/swc-linux-x64-gnu@14.0.1: + resolution: {integrity: sha512-wMqf90uDWN001NqCM/auRl3+qVVeKfjJdT9XW+RMIOf+rhUzadmYJu++tp2y+hUbb6GTRhT+VjQzcgg/QTD9NQ==} engines: {node: '>= 10'} cpu: [x64] os: [linux] requiresBuild: true optional: true - /@next/swc-linux-x64-musl@13.5.6: - resolution: {integrity: sha512-CFHvP9Qz98NruJiUnCe61O6GveKKHpJLloXbDSWRhqhkJdZD2zU5hG+gtVJR//tyW897izuHpM6Gtf6+sNgJPQ==} + /@next/swc-linux-x64-musl@14.0.1: + resolution: {integrity: sha512-ol1X1e24w4j4QwdeNjfX0f+Nza25n+ymY0T2frTyalVczUmzkVD7QGgPTZMHfR1aLrO69hBs0G3QBYaj22J5GQ==} engines: {node: '>= 10'} cpu: [x64] os: [linux] requiresBuild: true optional: true - /@next/swc-win32-arm64-msvc@13.5.6: - resolution: {integrity: sha512-aFv1ejfkbS7PUa1qVPwzDHjQWQtknzAZWGTKYIAaS4NMtBlk3VyA6AYn593pqNanlicewqyl2jUhQAaFV/qXsg==} + /@next/swc-win32-arm64-msvc@14.0.1: + resolution: {integrity: sha512-WEmTEeWs6yRUEnUlahTgvZteh5RJc4sEjCQIodJlZZ5/VJwVP8p2L7l6VhzQhT4h7KvLx/Ed4UViBdne6zpIsw==} engines: {node: '>= 10'} cpu: [arm64] os: [win32] requiresBuild: true optional: true - /@next/swc-win32-ia32-msvc@13.5.6: - resolution: {integrity: sha512-XqqpHgEIlBHvzwG8sp/JXMFkLAfGLqkbVsyN+/Ih1mR8INb6YCc2x/Mbwi6hsAgUnqQztz8cvEbHJUbSl7RHDg==} + /@next/swc-win32-ia32-msvc@14.0.1: + resolution: {integrity: sha512-oFpHphN4ygAgZUKjzga7SoH2VGbEJXZa/KL8bHCAwCjDWle6R1SpiGOdUdA8EJ9YsG1TYWpzY6FTbUA+iAJeww==} engines: {node: '>= 10'} cpu: [ia32] os: [win32] requiresBuild: true optional: true - /@next/swc-win32-x64-msvc@13.5.6: - resolution: {integrity: sha512-Cqfe1YmOS7k+5mGu92nl5ULkzpKuxJrP3+4AEuPmrpFZ3BHxTY3TnHmU1On3bFmFFs6FbTcdF58CCUProGpIGQ==} + /@next/swc-win32-x64-msvc@14.0.1: + resolution: {integrity: sha512-FFp3nOJ/5qSpeWT0BZQ+YE1pSMk4IMpkME/1DwKBwhg4mJLB9L+6EXuJi4JEwaJdl5iN+UUlmUD3IsR1kx5fAg==} engines: {node: '>= 10'} cpu: [x64] os: [win32] @@ -3516,7 +3516,7 @@ packages: react-colorful: 5.6.1(react-dom@18.0.0)(react@18.0.0) react-dom: 18.0.0(react@18.0.0) telejson: 7.2.0 - tocbot: 4.21.3 + tocbot: 4.21.6 ts-dedent: 2.2.0 util-deprecate: 1.0.2 transitivePeerDependencies: @@ -3649,7 +3649,7 @@ packages: commander: 6.2.1 cross-spawn: 7.0.3 detect-indent: 6.1.0 - envinfo: 7.10.0 + envinfo: 7.11.0 execa: 5.1.1 express: 4.18.2 find-up: 5.0.0 @@ -4051,7 +4051,7 @@ packages: resolution: {integrity: sha512-TXJJd5RAKakWx4BtpwvSNdgTDkKM6RkXU8GK34S/LhidQ5Pjz3wcnqb0TxEkfhK/ztbP8nKHqXFwLfa2CYkvQw==} dev: true - /@storybook/nextjs@7.5.0(@swc/core@1.3.95)(@types/react-dom@18.0.0)(@types/react@18.2.33)(esbuild@0.18.20)(next@13.5.6)(react-dom@18.0.0)(react@18.0.0)(typescript@5.2.2)(webpack@5.89.0): + /@storybook/nextjs@7.5.0(@swc/core@1.3.95)(@types/react-dom@18.0.0)(@types/react@18.2.33)(esbuild@0.18.20)(next@14.0.1)(react-dom@18.0.0)(react@18.0.0)(typescript@5.2.2)(webpack@5.89.0): resolution: {integrity: sha512-uMYD0yHc/TlfSPWhsD5zpsjbuwwRSE6AbNqYOaqwPLJewQGpL9KjYFMUFg6IZItv7JKmOVSeVKg+P2dUWhoFDA==} engines: {node: '>=16.0.0'} peerDependencies: @@ -4098,7 +4098,7 @@ packages: fs-extra: 11.1.1 image-size: 1.0.2 loader-utils: 3.2.1 - next: 13.5.6(@babel/core@7.23.2)(react-dom@18.0.0)(react@18.0.0) + next: 14.0.1(@babel/core@7.23.2)(react-dom@18.0.0)(react@18.0.0) node-polyfill-webpack-plugin: 2.0.1(webpack@5.89.0) pnp-webpack-plugin: 1.7.0(typescript@5.2.2) postcss: 8.4.31 @@ -5617,8 +5617,8 @@ packages: resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==} dev: true - /ast-types-flow@0.0.7: - resolution: {integrity: sha512-eBvWn1lvIApYMhzQMsu9ciLfkBY499mFZlNqG+/9WR7PVlroQw0vG30cOQQbaKz3sCEc44TAOu2ykzqXSNnwag==} + /ast-types-flow@0.0.8: + resolution: {integrity: sha512-OH/2E5Fg20h2aPrbe+QL8JZQFko0YZaF+j4mnQ7BGhfavO7OpSLa8a0y9sBwomHdSbkhTS8TQNayBfnW5DwbvQ==} dev: true /ast-types@0.14.2: @@ -5681,8 +5681,8 @@ packages: engines: {node: '>= 0.4'} dev: true - /axe-core@4.8.2: - resolution: {integrity: sha512-/dlp0fxyM3R8YW7MFzaHWXrf4zzbr0vaYb23VBFCl83R7nWNPg/yaQw2Dc8jzCMmDVLhSdzH8MjrsuIUuvX+6g==} + /axe-core@4.7.0: + resolution: {integrity: sha512-M0JtH+hlOL5pLQwHOLNYZaXuhqmvS8oExsqB1SBYgA4Dk7u/xx+YdGHXaK5pyUfed5mYXdlYiphWq3G8cRi5JQ==} engines: {node: '>=4'} dev: true @@ -5948,7 +5948,7 @@ packages: hasBin: true dependencies: caniuse-lite: 1.0.30001559 - electron-to-chromium: 1.4.571 + electron-to-chromium: 1.4.574 node-releases: 2.0.13 update-browserslist-db: 1.0.13(browserslist@4.22.1) @@ -6806,8 +6806,8 @@ packages: entities: 2.2.0 dev: true - /domain-browser@4.22.0: - resolution: {integrity: sha512-IGBwjF7tNk3cwypFNH/7bfzBcgSCbaMOD3GsaY1AU/JRrnHnYgEM0+9kQt52iZxjNsjBtJYtao146V+f8jFZNw==} + /domain-browser@4.23.0: + resolution: {integrity: sha512-ArzcM/II1wCCujdCNyQjXrAFwS4mrLh4C7DZWlaI8mdh7h3BfKdNd3bKXITfl2PT9FtfQqaGvhi1vPRQPimjGA==} engines: {node: '>=10'} dev: true @@ -6872,8 +6872,8 @@ packages: jake: 10.8.7 dev: true - /electron-to-chromium@1.4.571: - resolution: {integrity: sha512-Sc+VtKwKCDj3f/kLBjdyjMpNzoZsU6WuL/wFb6EH8USmHEcebxRXcRrVpOpayxd52tuey4RUDpUsw5OS5LhJqg==} + /electron-to-chromium@1.4.574: + resolution: {integrity: sha512-bg1m8L0n02xRzx4LsTTMbBPiUd9yIR+74iPtS/Ao65CuXvhVZHP0ym1kSdDG3yHFDXqHQQBKujlN1AQ8qZnyFg==} /elliptic@6.5.4: resolution: {integrity: sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==} @@ -6938,8 +6938,8 @@ packages: resolution: {integrity: sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==} dev: true - /envinfo@7.10.0: - resolution: {integrity: sha512-ZtUjZO6l5mwTHvc1L9+1q5p/R3wTopcfqMW8r5t8SJSKqeVI/LtajORwRFEKpEFuekjD0VBjwu1HMxL4UalIRw==} + /envinfo@7.11.0: + resolution: {integrity: sha512-G9/6xF1FPbIw0TtalAMaVPpiq2aDEuKLXM314jPVAO9r2fo2a4BLqMNkmRS7O/xPPZ+COAhGIz3ETvHEV3eUcg==} engines: {node: '>=4'} hasBin: true dev: true @@ -7161,7 +7161,7 @@ packages: eslint-import-resolver-node: 0.3.9 eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.9.1)(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.0)(eslint@8.0.0) eslint-plugin-import: 2.29.0(@typescript-eslint/parser@6.9.1)(eslint-import-resolver-typescript@3.6.1)(eslint@8.0.0) - eslint-plugin-jsx-a11y: 6.7.1(eslint@8.0.0) + eslint-plugin-jsx-a11y: 6.8.0(eslint@8.0.0) eslint-plugin-react: 7.33.2(eslint@8.0.0) eslint-plugin-react-hooks: 4.6.0(eslint@8.0.0) typescript: 5.2.2 @@ -7268,8 +7268,8 @@ packages: - supports-color dev: true - /eslint-plugin-jsx-a11y@6.7.1(eslint@8.0.0): - resolution: {integrity: sha512-63Bog4iIethyo8smBklORknVjB0T2dwB8Mr/hIC+fBS0uyHdYYpzM/Ed+YC8VxTjlXHEWFOdmgwcDn1U2L9VCA==} + /eslint-plugin-jsx-a11y@6.8.0(eslint@8.0.0): + resolution: {integrity: sha512-Hdh937BS3KdwwbBaKd5+PLCOmYY6U4f2h9Z2ktwtNKvIdIEu137rjYbcb9ApSbVJfWxANNuiKTD/9tOKjK9qOA==} engines: {node: '>=4.0'} peerDependencies: eslint: ^3 || ^4 || ^5 || ^6 || ^7 || ^8 @@ -7278,19 +7278,19 @@ packages: aria-query: 5.3.0 array-includes: 3.1.7 array.prototype.flatmap: 1.3.2 - ast-types-flow: 0.0.7 - axe-core: 4.8.2 + ast-types-flow: 0.0.8 + axe-core: 4.7.0 axobject-query: 3.2.1 damerau-levenshtein: 1.0.8 emoji-regex: 9.2.2 + es-iterator-helpers: 1.0.15 eslint: 8.0.0 - has: 1.0.4 + hasown: 2.0.0 jsx-ast-utils: 3.3.5 - language-tags: 1.0.5 + language-tags: 1.0.9 minimatch: 3.1.2 object.entries: 1.1.7 object.fromentries: 2.0.7 - semver: 6.3.1 dev: true /eslint-plugin-react-hooks@4.6.0(eslint@8.0.0): @@ -7859,7 +7859,7 @@ packages: dependencies: graceful-fs: 4.2.11 jsonfile: 6.1.0 - universalify: 2.0.0 + universalify: 2.0.1 dev: true /fs-extra@11.1.1: @@ -7868,7 +7868,7 @@ packages: dependencies: graceful-fs: 4.2.11 jsonfile: 6.1.0 - universalify: 2.0.0 + universalify: 2.0.1 dev: true /fs-minipass@2.1.0: @@ -8160,11 +8160,6 @@ packages: has-symbols: 1.0.3 dev: true - /has@1.0.4: - resolution: {integrity: sha512-qdSAmqLF6209RFj4VVItywPMbm3vWylknmB3nvNiUIs72xAimcM8nVYxYr7ncvZq5qzk9MKIZR8ijqD/1QuYjQ==} - engines: {node: '>= 0.4.0'} - dev: true - /hash-base@3.1.0: resolution: {integrity: sha512-1nmYp/rhMDiE7AYkDw+lLwlAzz0AntGIe51F3RfFfEqyQ3feY2eI/NcwC6umIQVOASPMsWJLJScWKSSvzL9IVA==} engines: {node: '>=4'} @@ -8962,7 +8957,7 @@ packages: /jsonfile@6.1.0: resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==} dependencies: - universalify: 2.0.0 + universalify: 2.0.1 optionalDependencies: graceful-fs: 4.2.11 dev: true @@ -9002,8 +8997,9 @@ packages: resolution: {integrity: sha512-tN0MCzyWnoz/4nHS6uxdlFWoUZT7ABptwKPQ52Ea7URk6vll88bWBVhodtnlfEuCcKWNGoc+uGbw1cwa9IKh/w==} dev: true - /language-tags@1.0.5: - resolution: {integrity: sha512-qJhlO9cGXi6hBGKoxEG/sKZDAHD5Hnu9Hs4WbOY3pCWXDhw0N8x1NenNzm2EnNLkLkk7J2SdxAkDSbb6ftT+UQ==} + /language-tags@1.0.9: + resolution: {integrity: sha512-MbjN408fEndfiQXbFQ1vnd+1NoLDsnQW41410oQBXiyXDMYH5z505juWa4KUE1LqxRC7DgOgZDbKLxHIwm27hA==} + engines: {node: '>=0.10'} dependencies: language-subtag-registry: 0.3.22 dev: true @@ -9564,21 +9560,21 @@ packages: resolution: {integrity: sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==} dev: true - /next-themes@0.2.1(next@13.5.6)(react-dom@18.0.0)(react@18.0.0): + /next-themes@0.2.1(next@14.0.1)(react-dom@18.0.0)(react@18.0.0): resolution: {integrity: sha512-B+AKNfYNIzh0vqQQKqQItTS8evEouKD7H5Hj3kmuPERwddR2TxvDSFZuTj6T7Jfn1oyeUyJMydPl1Bkxkh0W7A==} peerDependencies: next: '*' react: '*' react-dom: '*' dependencies: - next: 13.5.6(@babel/core@7.23.2)(react-dom@18.0.0)(react@18.0.0) + next: 14.0.1(@babel/core@7.23.2)(react-dom@18.0.0)(react@18.0.0) react: 18.0.0 react-dom: 18.0.0(react@18.0.0) dev: false - /next@13.5.6(@babel/core@7.23.2)(react-dom@18.0.0)(react@18.0.0): - resolution: {integrity: sha512-Y2wTcTbO4WwEsVb4A8VSnOsG1I9ok+h74q0ZdxkwM3EODqrs4pasq7O0iUxbcS9VtWMicG7f3+HAj0r1+NtKSw==} - engines: {node: '>=16.14.0'} + /next@14.0.1(@babel/core@7.23.2)(react-dom@18.0.0)(react@18.0.0): + resolution: {integrity: sha512-s4YaLpE4b0gmb3ggtmpmV+wt+lPRuGtANzojMQ2+gmBpgX9w5fTbjsy6dXByBuENsdCX5pukZH/GxdFgO62+pA==} + engines: {node: '>=18.17.0'} hasBin: true peerDependencies: '@opentelemetry/api': ^1.1.0 @@ -9591,7 +9587,7 @@ packages: sass: optional: true dependencies: - '@next/env': 13.5.6 + '@next/env': 14.0.1 '@swc/helpers': 0.5.2 busboy: 1.6.0 caniuse-lite: 1.0.30001559 @@ -9601,15 +9597,15 @@ packages: styled-jsx: 5.1.1(@babel/core@7.23.2)(react@18.0.0) watchpack: 2.4.0 optionalDependencies: - '@next/swc-darwin-arm64': 13.5.6 - '@next/swc-darwin-x64': 13.5.6 - '@next/swc-linux-arm64-gnu': 13.5.6 - '@next/swc-linux-arm64-musl': 13.5.6 - '@next/swc-linux-x64-gnu': 13.5.6 - '@next/swc-linux-x64-musl': 13.5.6 - '@next/swc-win32-arm64-msvc': 13.5.6 - '@next/swc-win32-ia32-msvc': 13.5.6 - '@next/swc-win32-x64-msvc': 13.5.6 + '@next/swc-darwin-arm64': 14.0.1 + '@next/swc-darwin-x64': 14.0.1 + '@next/swc-linux-arm64-gnu': 14.0.1 + '@next/swc-linux-arm64-musl': 14.0.1 + '@next/swc-linux-x64-gnu': 14.0.1 + '@next/swc-linux-x64-musl': 14.0.1 + '@next/swc-win32-arm64-msvc': 14.0.1 + '@next/swc-win32-ia32-msvc': 14.0.1 + '@next/swc-win32-x64-msvc': 14.0.1 transitivePeerDependencies: - '@babel/core' - babel-plugin-macros @@ -9664,7 +9660,7 @@ packages: console-browserify: 1.2.0 constants-browserify: 1.0.0 crypto-browserify: 3.12.0 - domain-browser: 4.22.0 + domain-browser: 4.23.0 events: 3.3.0 filter-obj: 2.0.2 https-browserify: 1.0.0 @@ -11857,8 +11853,8 @@ packages: dependencies: is-number: 7.0.0 - /tocbot@4.21.3: - resolution: {integrity: sha512-UKFkjz0nRB4s5WAeVnQJ3iIKmaKBbWDxzHYlRzJPZO7Doyp6v12nkJMN6T3HiMoQFHldvO1MZLAKRJqDMzkv2A==} + /tocbot@4.21.6: + resolution: {integrity: sha512-bAnyV6SU2n1AvuBvEgi8t7KiIn5rRiEmwFp4+elx/1ueuncAUyubITfXDMwOqStgUwh8pDzLdWgDKLicsJPikw==} dev: true /toidentifier@1.0.1: @@ -12137,8 +12133,8 @@ packages: unist-util-visit-parents: 3.1.1 dev: true - /universalify@2.0.0: - resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==} + /universalify@2.0.1: + resolution: {integrity: sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==} engines: {node: '>= 10.0.0'} dev: true diff --git a/src/app/layout.tsx b/src/app/layout.tsx index de39c683..d94332f8 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -12,15 +12,34 @@ import '@/styles/globals.css' export const metadata: Metadata = { title: '나비장터', description: '물물교환 플랫폼 나비장터입니다.', - viewport: 'width=device-width, initial-scale=1.0', } if (Environment.apiMocking() === 'enabled') { console.log('Mocking enabled') initMockApi() } +/* +const getIsLoggedIn = async () => { + try { + const cookieStore = cookies() + const token = cookieStore.get(Environment.tokenName()) + console.log(token?.value) + const res = await getValidateUser(token?.value) + const data = await res.json() + console.log(data, 'data') + if (data?.data?.userInfo) { + return true + } else { + return false + } + } catch (e) { + console.log(e) + return false + } +} +*/ -export default function RootLayout({ +export default async function RootLayout({ children, authModal, }: Readonly<{ @@ -30,21 +49,21 @@ export default function RootLayout({ return ( - - - + + + loading...}>
-
+
{children} {authModal}
-
-
-
+ + + ) diff --git a/src/components/domain/Header/Header.tsx b/src/components/domain/Header/Header.tsx index 0961432c..a8a4f586 100644 --- a/src/components/domain/Header/Header.tsx +++ b/src/components/domain/Header/Header.tsx @@ -1,23 +1,21 @@ +'use client' + import React from 'react' import Image from 'next/image' import Link from 'next/link' import Button from '@/components/ui/Button' -import { - DropdownMenu, - DropdownMenuTrigger, - DropdownMenuContent, - DropdownMenuGroup, - DropdownMenuItem, -} from '@/components/ui/DropdownMenu' import AppPath from '@/config/appPath' import Assets from '@/config/assets' +import { useAuth } from '@/contexts/AuthProvider' import Logo from '../Logo' +import { MenuButton, Avatar } from './section/Avatar' -type HeaderProps = { - isLogin?: boolean -} +// type HeaderProps = { +// isLogin?: boolean +// } -const Header = ({ isLogin = false }: HeaderProps) => { +const Header = () => { + const { isLoggedIn } = useAuth() return (
@@ -27,7 +25,7 @@ const Header = ({ isLogin = false }: HeaderProps) => {
- {isLogin ? ( + {isLoggedIn ? ( <> - - - - - 홈으로 - - - - - ) -} - -const Avatar = () => { - return ( - - - - - - - - 로그아웃 - - - - - ) -} diff --git a/src/components/domain/Header/section/Avatar.tsx b/src/components/domain/Header/section/Avatar.tsx new file mode 100644 index 00000000..424bd072 --- /dev/null +++ b/src/components/domain/Header/section/Avatar.tsx @@ -0,0 +1,57 @@ +import Cookies from 'js-cookie' +import Image from 'next/image' +import Link from 'next/link' +import Button from '@/components/ui/Button' +import { + DropdownMenu, + DropdownMenuTrigger, + DropdownMenuContent, + DropdownMenuGroup, + DropdownMenuItem, +} from '@/components/ui/DropdownMenu' +import AppPath from '@/config/appPath' +import Assets from '@/config/assets' +import { Environment } from '@/config/environment' + +//TODO: 공용 아바타 컴포넌트로 변경 + +const MenuButton = () => { + return ( + + + + + + + + 홈으로 + + + + + ) +} + +const Avatar = () => { + const onClickLogout = () => { + Cookies.remove(Environment.tokenName()) + location.reload() + } + + return ( + + + + + + + 로그아웃 + + + + ) +} + +export { MenuButton, Avatar } diff --git a/src/components/domain/LoginForm/LoginForm.tsx b/src/components/domain/LoginForm/LoginForm.tsx index 6aaf3bfe..aeb49459 100644 --- a/src/components/domain/LoginForm/LoginForm.tsx +++ b/src/components/domain/LoginForm/LoginForm.tsx @@ -9,6 +9,7 @@ import { Environment } from '@/config/environment' import { getGoogleLogin, getKakaoLogin } from '@/services/auth/auth' import LoginButtons from './section/LoginButtons' +//FIXME: 로그인 관련 로직은 추후에 따로 분리해야함 const LoginForm = () => { const router = useRouter() const kakaoLoginHandler = async () => { @@ -16,7 +17,6 @@ const LoginForm = () => { await getKakaoLogin() const res = await getKakaoLogin() const data = await res.json() - console.log(data) Cookies.set(Environment.tokenName(), data?.data?.token?.accessToken) alert('로그인 성공') router.back() @@ -31,7 +31,6 @@ const LoginForm = () => { await getKakaoLogin() const res = await getGoogleLogin() const data = await res.json() - console.log(data) Cookies.set(Environment.tokenName(), data?.data?.token?.accessToken) alert('로그인 성공') router.back() diff --git a/src/config/environment.ts b/src/config/environment.ts index 85c87900..105f16c1 100644 --- a/src/config/environment.ts +++ b/src/config/environment.ts @@ -2,9 +2,9 @@ export const Environment = { apiAddress: () => - process.env.NEXT_PUBLIC_API_MOCKING === 'enabled' - ? process.env.NEXT_PUBLIC_API_MOCKING_ADDRESS - : process.env.NEXT_PUBLIC_API_ADDRESS, + process.env.NEXT_PUBLIC_API_MOCKING === 'disabled' + ? process.env.NEXT_PUBLIC_API_ADDRESS + : process.env.NEXT_PUBLIC_API_MOCKING_ADDRESS, apiMocking: () => process.env.NEXT_PUBLIC_API_MOCKING === 'enabled' ? 'enabled' : 'disabled', tokenName: () => process.env.NEXT_PUBLIC_API_TOKEN_NAME ?? '', diff --git a/src/contexts/AuthProvider.tsx b/src/contexts/AuthProvider.tsx index e43a2f2f..57f1524e 100644 --- a/src/contexts/AuthProvider.tsx +++ b/src/contexts/AuthProvider.tsx @@ -1,6 +1,6 @@ 'use client' -import React, { createContext, useMemo } from 'react' +import React, { createContext, useMemo, useContext } from 'react' import useValidate from '@/hooks/useValidate' const AuthContext = createContext<{ @@ -25,7 +25,7 @@ const AuthProvider = ({ children }: { children: React.ReactNode }) => { } const useAuth = () => { - const context = React.useContext(AuthContext) + const context = useContext(AuthContext) if (context === undefined) { throw new Error(`useAuth must be used within a AuthProvider`) } diff --git a/src/hooks/useValidate.ts b/src/hooks/useValidate.ts index 463e7475..e415a9cb 100644 --- a/src/hooks/useValidate.ts +++ b/src/hooks/useValidate.ts @@ -1,3 +1,5 @@ +'use client' + import { useEffect, useState } from 'react' import { useQuery } from '@tanstack/react-query' import Cookies from 'js-cookie' @@ -14,7 +16,10 @@ const useValidate = () => { const { data, isError } = useQuery({ queryKey: ['validate', token], - queryFn: async () => await getValidateUser(token), + queryFn: async () => { + const res = await getValidateUser(token) + return await res.json() + }, enabled: !!token, }) @@ -26,10 +31,9 @@ const useValidate = () => { } if (data) { setIsLoggedIn(() => true) - setCurrentUser(() => data.data) + setCurrentUser(() => data?.data?.userInfo) } - console.log('validate', isLoggedIn, currentUser) - }, [data, isError, pathname, token]) + }, [currentUser, data, isError, isLoggedIn, pathname, token]) return { isLoggedIn, currentUser } } diff --git a/src/lib/fetchAPI.tsx b/src/lib/fetchAPI.tsx index 0d053daf..744c3a51 100644 --- a/src/lib/fetchAPI.tsx +++ b/src/lib/fetchAPI.tsx @@ -1,3 +1,5 @@ +import { Environment } from '@/config/environment' + class FetchAPI { private baseURL: string private headers: { [key: string]: string } @@ -5,7 +7,7 @@ class FetchAPI { private static instance: FetchAPI private constructor() { - this.baseURL = '' + this.baseURL = Environment.apiAddress() ?? '' this.headers = { 'Content-Type': 'application/json', } diff --git a/src/lib/msw/mocks/authHandlers.ts b/src/lib/msw/mocks/authHandlers.ts index 8afc7e18..3d757b73 100644 --- a/src/lib/msw/mocks/authHandlers.ts +++ b/src/lib/msw/mocks/authHandlers.ts @@ -41,6 +41,33 @@ const authHandlers = [ }), ) }), + rest.get( + `${baseUrl}${ApiEndPoint.getValidateUser()}`, + async (req, res, ctx) => { + const token = req.headers.get('Authorization')?.split(' ')[1] + if (!token || token === 'undefined') { + return res( + ctx.status(401), + ctx.json({ + message: '토큰이 존재하지 않습니다.', + }), + ) + } + + return res( + ctx.status(200), + ctx.json({ + data: { + userInfo: { + userId: 1, + nickname: '병원에 간 미어캣', + imageUrl: 'http://asdf~', + }, + }, + }), + ) + }, + ), ] export default authHandlers diff --git a/src/services/apiClient.ts b/src/services/apiClient.ts index ad838650..021cad0c 100644 --- a/src/services/apiClient.ts +++ b/src/services/apiClient.ts @@ -1,8 +1,5 @@ -import { Environment } from '@/config/environment' import FetchAPI from '@/lib/fetchAPI' const apiClient = FetchAPI.getInstance() -apiClient.setDefaultHeader('Content-Type', 'application/json') -apiClient.setBaseURL(Environment.apiAddress() ?? '') export default apiClient From bb13bce60e1de1e13c45aa9cdfb0b8dcae2ad889 Mon Sep 17 00:00:00 2001 From: oaoong Date: Fri, 3 Nov 2023 16:06:10 +0900 Subject: [PATCH 5/6] =?UTF-8?q?:bug:=20=EC=9D=98=EC=A1=B4=EC=84=B1=20?= =?UTF-8?q?=EB=AA=85=EC=84=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pnpm-lock.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6777d672..dc2269ad 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -108,7 +108,7 @@ devDependencies: version: 7.5.0(@types/react-dom@18.0.0)(@types/react@18.2.33)(encoding@0.1.13)(react-dom@18.0.0)(react@18.0.0) '@storybook/nextjs': specifier: 7.5.0 - version: 7.5.0(@swc/core@1.3.95)(@types/react-dom@18.0.0)(@types/react@18.2.33)(esbuild@0.18.20)(next@14.0.1)(react-dom@18.0.0)(react@18.0.0)(typescript@5.2.2)(webpack@5.89.0) + version: 7.5.0(@swc/core@1.3.95)(@types/react-dom@18.0.0)(@types/react@18.2.33)(encoding@0.1.13)(esbuild@0.18.20)(next@14.0.1)(react-dom@18.0.0)(react@18.0.0)(typescript@5.2.2)(webpack@5.89.0) '@storybook/react': specifier: 7.5.0 version: 7.5.0(encoding@0.1.13)(react-dom@18.0.0)(react@18.0.0)(typescript@5.2.2) @@ -4099,7 +4099,7 @@ packages: resolution: {integrity: sha512-TXJJd5RAKakWx4BtpwvSNdgTDkKM6RkXU8GK34S/LhidQ5Pjz3wcnqb0TxEkfhK/ztbP8nKHqXFwLfa2CYkvQw==} dev: true - /@storybook/nextjs@7.5.0(@swc/core@1.3.95)(@types/react-dom@18.0.0)(@types/react@18.2.33)(esbuild@0.18.20)(next@14.0.1)(react-dom@18.0.0)(react@18.0.0)(typescript@5.2.2)(webpack@5.89.0): + /@storybook/nextjs@7.5.0(@swc/core@1.3.95)(@types/react-dom@18.0.0)(@types/react@18.2.33)(encoding@0.1.13)(esbuild@0.18.20)(next@14.0.1)(react-dom@18.0.0)(react@18.0.0)(typescript@5.2.2)(webpack@5.89.0): resolution: {integrity: sha512-uMYD0yHc/TlfSPWhsD5zpsjbuwwRSE6AbNqYOaqwPLJewQGpL9KjYFMUFg6IZItv7JKmOVSeVKg+P2dUWhoFDA==} engines: {node: '>=16.0.0'} peerDependencies: From fc1cb8d59e1adf8e8380b249475e27a961fcfce7 Mon Sep 17 00:00:00 2001 From: oaoong Date: Fri, 3 Nov 2023 16:20:21 +0900 Subject: [PATCH 6/6] =?UTF-8?q?:sparkles:=20workflow=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pull-request.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index fb561511..c44571ec 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -23,13 +23,17 @@ jobs: - name: Install node uses: actions/setup-node@v4 with: - node-version: '16' + node-version: '20' cache: 'npm' cache-dependency-path: ./pnpm-lock.yaml + - uses: pnpm/action-setup@v2 + with: + version: 8 + # package.json에 명시된 의존성을 설치합니다. - name: Install Dependencies - run: npm install + run: pnpm install # 아래 단계에서 .env 파일을 생성하고 시크릿 값을 설정합니다. - name: Set Environment Variables @@ -46,11 +50,11 @@ jobs: # 빌드를 수행합니다. - name: Build - run: npm run build + run: pnpm build # 테스트를 수행합니다. - name: Run tests - run: npm run test + run: pnpm test - name: if_fail uses: actions/github-script@v4