261120_01_FIX: 삭제·권한 없는 프로젝트의 리스트 작업 기록이 남아 403이 반복 조회되는 문제 수정

This commit is contained in:
2026-11-20 15:49:06 +09:00
parent 88b36bf27d
commit 904bbd6509
5 changed files with 27 additions and 7 deletions

View File

@@ -2,11 +2,10 @@
import { useEffect } from 'react' import { useEffect } from 'react'
import { useAtom } from 'jotai' import { useAtom } from 'jotai'
import { HttpError } from '@kri/common/http'
import { Button } from '@/components/ui/button' import { Button } from '@/components/ui/button'
import { ListJobProgress } from '@/components/list/ListJobProgress' import { ListJobProgress } from '@/components/list/ListJobProgress'
import { useAuth } from '@/hooks/useAuth' import { useAuth } from '@/hooks/useAuth'
import { isAvailabilityUnsupported, useListJob, useListJobAvailability, useUploadResetActive } from '@/query/list-job' import { isAvailabilityUnsupported, isListJobGone, useListJob, useListJobAvailability, useUploadResetActive } from '@/query/list-job'
import { findTrackedListJob, trackListJob, untrackListJob, useTrackedListJobs } from '@/store/list-job-tracker' import { findTrackedListJob, trackListJob, untrackListJob, useTrackedListJobs } from '@/store/list-job-tracker'
import { listJobLabel } from '@/const/listJobConst' import { listJobLabel } from '@/const/listJobConst'
import { blockerJobLabel, blockerPhaseLabel, blockerUserLabel, describeListJobAvailability } from '@/utils/listJobAvailability' import { blockerJobLabel, blockerPhaseLabel, blockerUserLabel, describeListJobAvailability } from '@/utils/listJobAvailability'
@@ -45,7 +44,7 @@ export function useListJobGate({ prjctIdx, jobType, active, requestLabel, pollWh
const detail = useListJob(prjctIdx, jobKey, active) const detail = useListJob(prjctIdx, jobKey, active)
const job = detail.data?.jobKey === jobKey ? detail.data : undefined const job = detail.data?.jobKey === jobKey ? detail.data : undefined
const finishedJob = job && !isActiveListJob(job.jobStatus) ? job : undefined const finishedJob = job && !isActiveListJob(job.jobStatus) ? job : undefined
const detailNotFound = detail.error instanceof HttpError && detail.error.status === 404 const detailNotFound = isListJobGone(detail.error)
useEffect(() => { useEffect(() => {
if (!active && requestMatches && openRequest.opened) setOpenRequest(null) if (!active && requestMatches && openRequest.opened) setOpenRequest(null)

View File

@@ -4,10 +4,9 @@ import { useEffect } from 'react'
import { usePathname, useRouter } from 'next/navigation' import { usePathname, useRouter } from 'next/navigation'
import { useAtom } from 'jotai' import { useAtom } from 'jotai'
import { useQueries, useQueryClient } from '@tanstack/react-query' import { useQueries, useQueryClient } from '@tanstack/react-query'
import { HttpError } from '@kri/common/http'
import { toast } from 'sonner' import { toast } from 'sonner'
import { nextApi } from '@/lib/http-client' import { nextApi } from '@/lib/http-client'
import { listJobKeys, useMyActiveListJobs } from '@/query/list-job' import { isListJobGone, listJobKeys, useMyActiveListJobs } from '@/query/list-job'
import { listJobOpenRequestAtom } from '@/store/jotai/list-job' import { listJobOpenRequestAtom } from '@/store/jotai/list-job'
import { useSelectedProject } from '@/hooks/useSelectedProject' import { useSelectedProject } from '@/hooks/useSelectedProject'
import { useDialog } from '@/hooks/useDialog' import { useDialog } from '@/hooks/useDialog'
@@ -90,7 +89,7 @@ export function ListJobWatcher({ userId, prjctIdx }: { userId: string; prjctIdx:
details.forEach((result, index) => { details.forEach((result, index) => {
const tracked = trackedJobs[index] const tracked = trackedJobs[index]
if (!tracked) return if (!tracked) return
if (result.error instanceof HttpError && result.error.status === 404) { if (isListJobGone(result.error)) {
untrackListJob(tracked.jobKey) untrackListJob(tracked.jobKey)
return return
} }

View File

@@ -1,9 +1,12 @@
"use client"; "use client";
import { useMutation, useQueryClient } from "@tanstack/react-query"; import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useSetAtom } from "jotai";
import { nextApi } from "@/lib/http-client"; import { nextApi } from "@/lib/http-client";
import { useAuth } from "@/hooks/useAuth"; import { useAuth } from "@/hooks/useAuth";
import { useSelectedProject } from "@/hooks/useSelectedProject"; import { useSelectedProject } from "@/hooks/useSelectedProject";
import { clearTrackedListJobs } from "@/store/list-job-tracker";
import { listJobOpenRequestAtom } from "@/store/jotai/list-job";
import type { LoginUser } from "@kri/common"; import type { LoginUser } from "@kri/common";
export const useLoginMutation = () => { export const useLoginMutation = () => {
@@ -31,6 +34,7 @@ export const useLogoutMutation = () => {
const qc = useQueryClient(); const qc = useQueryClient();
const { auth, logout } = useAuth(); const { auth, logout } = useAuth();
const { clearSelectedProject } = useSelectedProject(); const { clearSelectedProject } = useSelectedProject();
const setListJobOpenRequest = useSetAtom(listJobOpenRequestAtom);
return useMutation({ return useMutation({
mutationFn: async () => { mutationFn: async () => {
@@ -49,6 +53,8 @@ export const useLogoutMutation = () => {
}, },
onSettled: () => { onSettled: () => {
clearSelectedProject(); clearSelectedProject();
clearTrackedListJobs();
setListJobOpenRequest(null);
logout(); logout();
qc.clear(); // 다음 사용자/세션에 서버상태 남지 않게 qc.clear(); // 다음 사용자/세션에 서버상태 남지 않게
}, },

View File

@@ -38,6 +38,14 @@ const fetchAvailability = async (prjctIdx: number, jobType: ListJobType) =>
/** 신규 API 미배포·롤백 상태. 반복 호출하지 않고 사전 안내만 중단한다. */ /** 신규 API 미배포·롤백 상태. 반복 호출하지 않고 사전 안내만 중단한다. */
export const isAvailabilityUnsupported = (error: unknown) => error instanceof HttpError && error.status === 404 export const isAvailabilityUnsupported = (error: unknown) => error instanceof HttpError && error.status === 404
/**
* 작업을 더 이상 조회할 수 없는 경우. 기록을 지우고 반복 조회를 멈춘다.
* - 404: 작업이 만료됐거나 내 작업이 아니다.
* - 403 PROJECT_ACCESS_DENIED: 프로젝트가 삭제됐거나 접근 권한·배정·상태가 바뀌었다.
*/
export const isListJobGone = (error: unknown) => error instanceof HttpError
&& (error.status === 404 || (error.status === 403 && apiError(error).code === 'PROJECT_ACCESS_DENIED'))
export function useSubmitListJob(prjctIdx: number) { export function useSubmitListJob(prjctIdx: number) {
const qc = useQueryClient() const qc = useQueryClient()
const { auth } = useAuth() const { auth } = useAuth()

View File

@@ -1,7 +1,7 @@
'use client' 'use client'
import { useSyncExternalStore } from 'react' import { useSyncExternalStore } from 'react'
import { getLocalStorage, setLocalStorage } from '@/store/storage/secure-storage' import { getLocalStorage, removeLocalStorage, setLocalStorage } from '@/store/storage/secure-storage'
import { StorageKeys } from '@/store/storage/storage-keys' import { StorageKeys } from '@/store/storage/storage-keys'
import { isListJobType, type ListJobType } from '@/types/list-job' import { isListJobType, type ListJobType } from '@/types/list-job'
@@ -77,6 +77,14 @@ export const untrackListJob = (jobKey: string) => {
write(jobs.filter((job) => job.jobKey !== jobKey)) write(jobs.filter((job) => job.jobKey !== jobKey))
} }
/** 로그아웃 시 다음 사용자에게 기록이 남지 않게 모두 지운다. 진행 중인 작업은 재로그인 후 my-active 조회로 다시 채워진다. */
export const clearTrackedListJobs = () => {
if (typeof window === 'undefined') return
removeLocalStorage(StorageKeys.ListJobs)
cache = EMPTY
window.dispatchEvent(new Event(CHANGE_EVENT))
}
export const findTrackedListJob = (jobs: TrackedListJob[], userId: string, prjctIdx: number, jobType: ListJobType) => export const findTrackedListJob = (jobs: TrackedListJob[], userId: string, prjctIdx: number, jobType: ListJobType) =>
jobs.find((job) => job.userId === userId && job.prjctIdx === prjctIdx && job.jobType === jobType) jobs.find((job) => job.userId === userId && job.prjctIdx === prjctIdx && job.jobType === jobType)