Skip to content

Commit

Permalink
Merge pull request #114 from doghae/kiyeong
Browse files Browse the repository at this point in the history
feat: 퀴즈페이지 마무리
  • Loading branch information
gogumalatte authored Aug 6, 2024
2 parents 71da94b + 27675ec commit ec2fc45
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/pages/Home/QuizScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ec2fc45

Please sign in to comment.