Fix: 피드백 반영 수정
This commit is contained in:
parent
5edfe33564
commit
2ec98c0ece
@ -30,9 +30,9 @@ const processQueue = (error: Error | null, token: string | undefined = undefined
|
|||||||
};
|
};
|
||||||
|
|
||||||
api.interceptors.request.use((config: InternalAxiosRequestConfig) => {
|
api.interceptors.request.use((config: InternalAxiosRequestConfig) => {
|
||||||
const token = sessionStorage.getItem('accessToken');
|
const accessToken = useAuthStore.getState().accessToken;
|
||||||
if (token && config.headers) {
|
if (accessToken && config.headers) {
|
||||||
config.headers.Authorization = `Bearer ${token}`;
|
config.headers.Authorization = `Bearer ${accessToken}`;
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@ -72,13 +72,12 @@ api.interceptors.response.use(
|
|||||||
}
|
}
|
||||||
|
|
||||||
useAuthStore.getState().setLoggedIn(true, newAccessToken);
|
useAuthStore.getState().setLoggedIn(true, newAccessToken);
|
||||||
sessionStorage.setItem('accessToken', newAccessToken);
|
|
||||||
processQueue(null, newAccessToken);
|
processQueue(null, newAccessToken);
|
||||||
|
|
||||||
if (originalRequest.headers) {
|
const redirectUri = `/redirect/oauth2?accessToken=${newAccessToken}`;
|
||||||
originalRequest.headers.Authorization = `Bearer ${newAccessToken}`;
|
window.location.href = redirectUri;
|
||||||
}
|
|
||||||
return api(originalRequest);
|
return Promise.reject(new Error('Redirecting to retrieve cookies'));
|
||||||
} catch (reissueError: unknown) {
|
} catch (reissueError: unknown) {
|
||||||
processQueue(reissueError as Error, undefined);
|
processQueue(reissueError as Error, undefined);
|
||||||
console.error('토큰 재발급 실패:', reissueError);
|
console.error('토큰 재발급 실패:', reissueError);
|
||||||
|
@ -11,12 +11,10 @@ const DOMAIN = 'https://j11s002.p.ssafy.io';
|
|||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { isLoggedIn, setLoggedIn, profile, setProfile } = useAuthStore();
|
const { isLoggedIn, accessToken, setLoggedIn, profile, setProfile } = useAuthStore();
|
||||||
const hasFetchedProfile = useRef(false);
|
const hasFetchedProfile = useRef(false);
|
||||||
|
|
||||||
if (!isLoggedIn && !profile && !hasFetchedProfile.current) {
|
if (!isLoggedIn && !profile && !hasFetchedProfile.current && accessToken) {
|
||||||
const accessToken = sessionStorage.getItem('accessToken');
|
|
||||||
if (accessToken) {
|
|
||||||
setLoggedIn(true, accessToken);
|
setLoggedIn(true, accessToken);
|
||||||
fetchProfileApi()
|
fetchProfileApi()
|
||||||
.then((data: SuccessResponse<MemberResponseDTO>) => {
|
.then((data: SuccessResponse<MemberResponseDTO>) => {
|
||||||
@ -30,7 +28,6 @@ export default function Home() {
|
|||||||
console.error('프로필 가져오기 실패:', error?.response?.data?.message || '알 수 없는 오류');
|
console.error('프로필 가져오기 실패:', error?.response?.data?.message || '알 수 없는 오류');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const handleGoogleSignIn = () => {
|
const handleGoogleSignIn = () => {
|
||||||
window.location.href = `${DOMAIN}/api/login/oauth2/authorization/google`;
|
window.location.href = `${DOMAIN}/api/login/oauth2/authorization/google`;
|
||||||
|
@ -6,6 +6,7 @@ import { fetchProfileApi } from '@/api/authApi';
|
|||||||
export default function OAuthCallback() {
|
export default function OAuthCallback() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const setLoggedIn = useAuthStore((state) => state.setLoggedIn);
|
const setLoggedIn = useAuthStore((state) => state.setLoggedIn);
|
||||||
|
const setProfile = useAuthStore((state) => state.setProfile);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const queryParams = new URLSearchParams(window.location.search);
|
const queryParams = new URLSearchParams(window.location.search);
|
||||||
@ -13,7 +14,6 @@ export default function OAuthCallback() {
|
|||||||
|
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
setLoggedIn(true, accessToken);
|
setLoggedIn(true, accessToken);
|
||||||
sessionStorage.setItem('accessToken', accessToken);
|
|
||||||
|
|
||||||
fetchProfileApi()
|
fetchProfileApi()
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
@ -23,7 +23,7 @@ export default function OAuthCallback() {
|
|||||||
nickname: data.data.nickname,
|
nickname: data.data.nickname,
|
||||||
profileImage: data.data.profileImage,
|
profileImage: data.data.profileImage,
|
||||||
};
|
};
|
||||||
useAuthStore.getState().setProfile(profileData);
|
setProfile(profileData);
|
||||||
navigate('/browse');
|
navigate('/browse');
|
||||||
} else {
|
} else {
|
||||||
throw new Error('프로필 데이터를 가져올 수 없습니다.');
|
throw new Error('프로필 데이터를 가져올 수 없습니다.');
|
||||||
@ -37,7 +37,7 @@ export default function OAuthCallback() {
|
|||||||
} else {
|
} else {
|
||||||
navigate('/');
|
navigate('/');
|
||||||
}
|
}
|
||||||
}, [navigate, setLoggedIn]);
|
}, [navigate, setLoggedIn, setProfile]);
|
||||||
|
|
||||||
return <p>처리 중입니다...</p>;
|
return <p>처리 중입니다...</p>;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ export const webPath = {
|
|||||||
workspace: () => '/workspace',
|
workspace: () => '/workspace',
|
||||||
// workspace: (workspaceId: string, projectId?: string) =>
|
// workspace: (workspaceId: string, projectId?: string) =>
|
||||||
// projectId ? `/workspace/${workspaceId}/project/${projectId}` : `/workspace/${workspaceId}`,
|
// projectId ? `/workspace/${workspaceId}/project/${projectId}` : `/workspace/${workspaceId}`,
|
||||||
admin: (workspaceId: string) => `/admin/${workspaceId}`,
|
admin: () => `/admin`,
|
||||||
oauthCallback: () => '/redirect/oauth2',
|
oauthCallback: () => '/redirect/oauth2',
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ const router = createBrowserRouter([
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: webPath.admin(':workspaceId'),
|
path: `${webPath.admin()}/:workspaceId`,
|
||||||
element: <AdminLayout />,
|
element: <AdminLayout />,
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,6 @@ const useAuthStore = create<AuthState>()(
|
|||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
name: 'auth-storage',
|
name: 'auth-storage',
|
||||||
getStorage: () => sessionStorage,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user