Skip to content

fix: 대기→시험 전환 시 tokenLimit 갱신 및 admin 401 리다이렉트#25

Merged
ydking0911 merged 2 commits into
developfrom
fix/#24/관리자-시험-세션-처리에-대한-버그-수정
Apr 26, 2026

Hidden character warning

The head ref may contain hidden characters: "fix/#24/\uad00\ub9ac\uc790-\uc2dc\ud5d8-\uc138\uc158-\ucc98\ub9ac\uc5d0-\ub300\ud55c-\ubc84\uadf8-\uc218\uc815"
Merged

fix: 대기→시험 전환 시 tokenLimit 갱신 및 admin 401 리다이렉트#25
ydking0911 merged 2 commits into
developfrom
fix/#24/관리자-시험-세션-처리에-대한-버그-수정

Conversation

@ydking0911
Copy link
Copy Markdown
Member

@ydking0911 ydking0911 commented Apr 14, 2026

개요

대기 화면에서 시험으로 전환 시 최신 tokenLimit이 반영되지 않는 버그와,
관리자 토큰 만료 시 버튼이 조용히 실패하는 UX 문제를 수정합니다.

배경 / 원인

  1. tokenLimit 미반영: waiting/page.tsx는 RUNNING 감지 시 store를 갱신 없이 바로
    /test로 이동했습니다. Zustand store의 tokenLimit은 enterExam 시점 값이므로,
    관리자가 시험 시작 전 tokenLimit을 변경해도 참가자 화면에 반영되지 않았습니다.

  2. admin 401 무음 실패: startExam·endExam·deleteExam API가 401을 반환할 때
    에러를 throw만 하고 별도 처리가 없어, 버튼이 조용히 실패했습니다.

변경 사항

waiting → test 전환 시 세션 재조회 (#BUG-1)

lib/api/exams.ts

  • ParticipantSessionResponse 타입 추가
  • getParticipantSession(examId) 함수 추가 (GET /api/exams/{examId}/participants/me)

app/waiting/page.tsx

  • RUNNING 감지 시 세션 재조회 → tokenLimit store 갱신 후 /test 이동
  • 재조회 실패해도 /test 이동은 보장 (기존 tokenLimit 유지 fallback)

admin 401 리다이렉트 (#BUG-2)

lib/api/admin.ts

  • handleAdminAuthError(status) 유틸 추가 — 401 시 /?auth_expired=1 리다이렉트
    (window.location.href 사용으로 Next.js 라우터 외부 동작 보장)
  • startExam / endExam / deleteExam 401 블록에 적용
  • CreateEntryCodeRequest 인터페이스에 tokenLimit?: number 추가
  • EntryCodeResponse 인터페이스에 tokenLimit: number 추가 (BE 응답 필드 동기화)

관련 이슈

closes #24

체크리스트

  • 세션 재조회 실패 시 기존값 유지 fallback 처리
  • SSR 환경 고려 (typeof window !== 'undefined' 가드)
  • BE ParticipantSessionResponse 스펙과 타입 일치
  • FE 타입과 BE 응답 필드 동기화 (tokenLimit)

@ydking0911 ydking0911 self-assigned this Apr 14, 2026
@ydking0911 ydking0911 added the fix label Apr 14, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vibecodeeval Ready Ready Preview, Comment Apr 26, 2026 3:13am

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

대기 화면에서 시험 시작(RUNNING) 전환 시 최신 tokenLimit이 반영되지 않던 문제를 해결하고, 관리자 API에서 401 발생 시 사용자에게 명확한 리다이렉트를 제공하도록 개선합니다.

Changes:

  • 참가자 세션 재조회 API(GET /api/exams/{examId}/participants/me) 및 응답 타입 추가
  • 대기 화면에서 RUNNING 감지 시 세션 재조회로 tokenLimit 갱신 후 /test로 이동 (실패 시 기존 값 유지)
  • 관리자 start/end/delete API에서 401 시 /?auth_expired=1로 리다이렉트 처리 및 EntryCode 타입에 tokenLimit 필드 동기화

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
lib/api/exams.ts 참가자 세션 조회 타입/함수 추가로 최신 tokenLimit 재조회 기반 마련
app/waiting/page.tsx RUNNING 전환 시 세션 재조회 후 store 갱신 및 /test 이동 로직 추가
lib/api/admin.ts 401 공통 처리 유틸 추가 및 일부 관리자 API에 리다이렉트 적용, entry-code 타입에 tokenLimit 반영

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/waiting/page.tsx
Comment on lines +34 to +38
const session = await getParticipantSession(examId);
useExamSessionStore.setState({ tokenLimit: session.tokenLimit });
} catch (sessionErr) {
// 세션 갱신 실패해도 화면 이동은 진행 (기존 값 유지)
console.warn("[WaitingPage] getParticipantSession 실패, 기존 tokenLimit 유지:", sessionErr);
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cancelled 플래그를 getExamState 이후에만 확인하고 있어서, getParticipantSession 대기 중에 cleanup이 실행되면(예: examId 변경/페이지 이탈) unmount 이후에도 setState/router.push가 실행될 수 있습니다. 세션 조회 후에도 if (cancelled) return;을 다시 체크하거나, RUNNING 감지 시 interval을 즉시 정리하고 나서 store 갱신 및 이동을 처리해 레이스를 막아주세요.

Copilot uses AI. Check for mistakes.
Comment thread lib/api/admin.ts Outdated

/**
* 401 Unauthorized 처리 공통 함수
* access token이 만료된 경우 로그인 페이지로 리다이렉트한다.
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석에서 “로그인 페이지로 리다이렉트”라고 되어 있는데, 실제 구현은 window.location.href = '/?auth_expired=1'로 홈으로 이동합니다. 의도가 홈 이동이라면 주석을 맞춰 수정하고, 정말 로그인 페이지로 보내야 한다면 URL을 주석과 일치시키는 쪽으로 정리해주세요.

Suggested change
* access token이 만료된 경우 로그인 페이지로 리다이렉트한다.
* access token이 만료된 경우 홈으로 리다이렉트한다.

Copilot uses AI. Check for mistakes.
Comment thread lib/api/admin.ts Outdated
Comment on lines +41 to +42
// 쿠키 기반 인증이므로 클라이언트 쿠키 정리 후 홈으로 이동
// (HttpOnly 쿠키는 BE 로그아웃 엔드포인트가 삭제하므로 여기서는 홈 이동만 처리)
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“클라이언트 쿠키 정리 후 홈으로 이동”이라고 되어 있지만, 이 함수는 쿠키/스토리지 정리 작업을 수행하지 않고 단순히 location 변경만 합니다. 오해를 줄이기 위해 주석에서 ‘쿠키 정리’ 관련 표현을 제거하거나, 실제로 정리해야 하는 항목이 있다면(예: localStorage 토큰 등) 코드로 명확히 처리해주세요.

Suggested change
// 쿠키 기반 인증이므로 클라이언트 쿠키 정리 후 홈으로 이동
// (HttpOnly 쿠키는 BE 로그아웃 엔드포인트가 삭제하므로 여기서는 홈 이동만 처리)
// 쿠키 기반 인증이며 HttpOnly 쿠키 삭제는 BE에서 처리한다.
// 여기서는 인증 만료 상태를 표시하며 홈으로 이동만 처리한다.

Copilot uses AI. Check for mistakes.
@ydking0911 ydking0911 merged commit 5b6d8f3 into develop Apr 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants