Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] accessToken api 호출 url 변경 #1551 #1563

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hooks/agenda/useFetchGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const useFetchGet = <T>({ url, isReady = true, params }: FetchGetProps) => {
}, [url, isReady, params]);

useEffect(() => {
if (url) {
if (url && isReady) {
getData(); // 조건에 맞을 때만 getData 호출
}
}, [url, isReady, JSON.stringify(params)]);
Expand Down
6 changes: 3 additions & 3 deletions hooks/useAxiosAgendaError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AxiosError, AxiosResponse } from 'axios';
import Cookies from 'js-cookie';
import { useEffect, useState } from 'react';
import { useSetRecoilState } from 'recoil';
import { instanceInAgenda } from 'utils/axios';
import { instanceInAgenda, instance } from 'utils/axios';
import { agendaErrorState } from 'utils/recoil/agendaError';
import { loginState } from 'utils/recoil/login';

Expand All @@ -17,7 +17,7 @@ export default function useAxiosAgendaError() {
return;
}
try {
const res = await instanceInAgenda.post(
const res = await instance.post(
`/pingpong/users/accesstoken?refreshToken=${refreshToken}`
);
localStorage.setItem('42gg-token', res.data.accessToken);
Expand All @@ -42,7 +42,7 @@ export default function useAxiosAgendaError() {
if (!isRecalling) {
setIsRecalling(true);
try {
const res = await instanceInAgenda.post(
const res = await instance.post(
`/pingpong/users/accesstoken?refreshToken=${refreshToken}`
);
localStorage.setItem('42gg-token', res.data.accessToken);
Expand Down
17 changes: 4 additions & 13 deletions pages/agenda/profile/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ const AgendaProfile = () => {
const [isIntraId, setIsIntraId] = useState<boolean>(false); // 인트라 아이디가 42에 있는지 확인
const [isAgendaId, setIsAgendaId] = useState<boolean>(false); // 인트라 아이디가 agenda에 있는지 확인
const [activeTab, setActiveTab] = useState('current'); // 현재 활성화된 탭 상태 관리
const [agendaProfileData, setAgendaProfileData] =
useState<AgendaProfileDataProps | null>(null); // agendaProfileData 상태 추가

/** API GET */
// GET: intraData (42 인트라 데이터 가져오기)
Expand All @@ -36,7 +34,7 @@ const AgendaProfile = () => {
isReady: Boolean(queryIntraId),
});
// GET: agendaProfileData (GG 아젠다 유저 데이터 가져오기)
const { data: fetchedAgendaProfileData, getData: getAgendaProfileData } =
const { data: agendaProfileData, getData: getAgendaProfileData } =
useFetchGet<AgendaProfileDataProps>({
url: `/profile/${queryIntraId}`,
isReady: isIntraId,
Expand Down Expand Up @@ -80,20 +78,13 @@ const AgendaProfile = () => {
// 2. intraData가 있으면 인트라 아이디가 42에 있다는 뜻이므로 isIntraId = true
setIsIntraId(!!intraData);
// 3. agendaProfileData가 있으면 아젠다에 등록된 사용자이므로 isAgendaId = true
setIsAgendaId(!!fetchedAgendaProfileData);
if (isAgendaId) {
setAgendaProfileData(fetchedAgendaProfileData);
} else {
setAgendaProfileData(null); // fetchedAgendaProfileData가 없을 때 초기화
}
setIsAgendaId(!!agendaProfileData);
};
updateProfileStatus();
}, [queryIntraId, intraData, fetchedAgendaProfileData]);

useEffect(() => {
setIsIntraId(false);
setIsAgendaId(false);
}, [queryIntraId]);
updateProfileStatus();
}, [queryIntraId, intraData, agendaProfileData]);

/** UI Rendering */
if (!queryIntraId || !myIntraId) {
Expand Down