From 27675ecb8327ddfd99b3652bbadbdb638c3be2b3 Mon Sep 17 00:00:00 2001 From: kiyeong Date: Tue, 6 Aug 2024 23:33:04 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=80=B4=EC=A6=88=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EB=A7=88=EB=AC=B4=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Home/QuizScreen.tsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/pages/Home/QuizScreen.tsx b/src/pages/Home/QuizScreen.tsx index 2a957cd..01ae079 100644 --- a/src/pages/Home/QuizScreen.tsx +++ b/src/pages/Home/QuizScreen.tsx @@ -18,6 +18,26 @@ export const Quiz = () => { const { state, dispatch } = useUser(); // UserContext 사용, 닉네임 가져오기 + useEffect(() => { + if (token) { + fetchNickname(token); + } + }, [token]); + + const fetchNickname = async (token: string) => { + try { + const response = await axios.get("https://doghae.site/user/nickname", { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + const nickname = response.data.data; // 닉네임 추출 + dispatch({ type: "SET_NICKNAME", payload: nickname }); // 상태 업데이트 + } catch (error) { + console.error("데이터 가져오기 실패", error); + } + }; + useEffect(() => { const storedToken = localStorage.getItem("token"); setToken(storedToken);