Skip to content

어드민 로그인 계정에 따라 dev/prod API 서버 런타임 자동 전환 - #615

Merged
whqtker merged 2 commits into
mainfrom
feat/admin-runtime-api-env-switch
Aug 1, 2026
Merged

어드민 로그인 계정에 따라 dev/prod API 서버 런타임 자동 전환#615
whqtker merged 2 commits into
mainfrom
feat/admin-runtime-api-env-switch

Conversation

@whqtker

@whqtker whqtker commented Aug 1, 2026

Copy link
Copy Markdown
Member

요약

  • 어드민 웹(apps/admin)은 서브도메인이 하나뿐이라 web/university-web처럼 .env.development/.env.production 빌드타임 분리를 쓸 수 없었음. 로그인 이메일이 @dev.solid-connection.com 도메인이면 stage API, 그 외는 prod API로 로그인 요청 및 이후 모든 API 호출이 런타임에 라우팅되도록 변경
  • 선택된 환경은 localStorage에 저장되어 새로고침 후에도 유지되고, 화면에 현재 환경(DEV/PROD/LOCAL) 배지를 표시
  • axios 인스턴스는 요청 인터셉터에서 매 요청마다 baseURL을 재계산해 런타임 전환을 지원. 로컬 개발용 VITE_API_SERVER_URL override는 vinext dev 모드에서만 적용되어, Vercel에 값이 남아있어도 배포본에는 영향 없음
  • 재로그인 시 이전 환경의 토큰을 먼저 제거해, 환경 전환 시 토큰이 다른 환경으로 새어나가는 경합(race)을 차단
  • 부수적으로 마이그레이션 안 됐던 Bruno API 콘솔의 원격 서버 경고, 채팅 소켓 테스트 페이지의 기본 서버 URL도 동일한 런타임 resolver로 통일

배경

딥 인터뷰(Socratic Q&A, 7라운드)로 요구사항을 정리하고, 별도 code-reviewer 에이전트 검토(HIGH 3건 포함)를 반영해 구현했습니다.

Test plan

  • pnpm --filter admin typecheck
  • pnpm --filter admin lint:check
  • pnpm --filter admin test (25 tests passed, 신규 environment.test.ts 포함)
  • pnpm --filter admin build
  • 실제 브라우저에서 dev/prod 이메일 로그인 후 네트워크 탭으로 호출 대상 API 확인
  • 새로고침 후 환경 유지, 재로그인 시 환경 전환, 로그아웃 시 정리 확인

어드민 웹은 서브도메인이 하나뿐이라 web/university-web처럼 빌드타임
.env.development/.env.production 분리가 불가능하다. 로그인 이메일이
@dev.solid-connection.com 도메인이면 stage API로, 그 외는 prod API로
로그인 요청 및 이후 모든 API 호출을 런타임에 라우팅하도록 변경했다.

- 선택된 환경은 localStorage에 저장되어 새로고침 후에도 유지되고,
  화면에 현재 환경(DEV/PROD)을 배지로 표시한다.
- axios 인스턴스는 요청 인터셉터에서 baseURL을 매번 재계산해 런타임
  전환을 지원하며, 로컬 개발용 VITE_API_SERVER_URL override는
  vinext dev 모드에서만 적용된다.
- 재로그인 시 이전 환경의 토큰을 먼저 제거해 다른 환경으로 토큰이
  새어나가는 경합을 차단했다.
@whqtker
whqtker requested review from manNomi and wibaek as code owners August 1, 2026 12:17
@vercel

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
solid-connect-university-web Ready Ready Preview Aug 1, 2026 12:32pm
solid-connect-web-admin Ready Ready Preview Aug 1, 2026 12:32pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
solid-connection-web Skipped Skipped Aug 1, 2026 12:32pm

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@whqtker, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 62d8619e-9bb4-43c9-b9f4-938b0bd39108

📥 Commits

Reviewing files that changed from the base of the PR and between 82f0be5 and 1670eb9.

📒 Files selected for processing (2)
  • apps/admin/src/lib/api/auth.test.ts
  • apps/admin/src/lib/api/auth.ts

Walkthrough

  1. 환경 판별과 저장
    이메일 도메인으로 dev 또는 prod를 판별하고, 환경값과 API URL을 관리합니다.
  2. 인증과 요청 적용
    로그인 환경을 저장하고, Axios 요청마다 활성 API 기본 URL을 적용합니다.
  3. 관리자 화면 반영
    로컬 개발 override를 선택 사항으로 변경하고, 환경 배너와 API 사용 위치를 갱신합니다.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: wibaek, mannomi

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 로그인 이메일에 따른 dev/prod API 서버의 런타임 자동 전환이라는 주요 변경을 정확하고 간결하게 설명합니다.
Description check ✅ Passed 관련 이슈와 템플릿 제목은 없지만 작업 내용, 배경, 테스트 계획과 미검증 항목을 충분히 설명합니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/admin-runtime-api-env-switch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/admin/src/lib/api/auth.ts`:
- Around line 21-23: Update saveAdminApiEnvironment to return whether
localStorage persistence succeeded, then update the sign-in flow around
saveAdminApiEnvironment in the auth request to abort before
authAxiosInstance.post when saving the resolved environment fails. Preserve the
existing token removal and successful-login request behavior, and add a
regression test confirming localStorage.setItem failures prevent the request
from being sent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 24aa8b54-5936-40de-8e51-76ab60aa5a30

📥 Commits

Reviewing files that changed from the base of the PR and between 626b042 and 82f0be5.

📒 Files selected for processing (12)
  • apps/admin/.env.example
  • apps/admin/src/components/features/bruno/BrunoApiPageContent.tsx
  • apps/admin/src/components/features/chat-socket/ChatSocketPageContent.tsx
  • apps/admin/src/components/layout/AdminLayout.tsx
  • apps/admin/src/components/layout/EnvironmentBanner.tsx
  • apps/admin/src/lib/api/auth.ts
  • apps/admin/src/lib/api/client.ts
  • apps/admin/src/lib/auth/environment.test.ts
  • apps/admin/src/lib/auth/environment.ts
  • apps/admin/src/lib/auth/session.ts
  • apps/admin/src/lib/env.ts
  • apps/admin/src/lib/utils/localStorage.ts

Comment thread apps/admin/src/lib/api/auth.ts Outdated
Comment on lines 21 to 23
removeAccessToken();
saveAdminApiEnvironment(resolveEnvironmentFromEmail(email));
return authAxiosInstance.post("/auth/email/sign-in", { email, password });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

1. 환경 저장에 실패하면 로그인 요청을 중단하십시오.

Line 22의 saveAdminApiEnvironmentlocalStorage 오류를 내부에서 처리하고 성공 여부를 반환하지 않습니다. 저장이 실패하면 요청 인터셉터는 환경을 읽지 못하고 production URL을 선택합니다. 그러면 dev 계정의 이메일과 비밀번호가 production API로 전송됩니다.

saveAdminApiEnvironment가 성공 여부를 반환하게 하십시오. 저장에 실패하면 Line 23의 로그인 요청을 보내지 마십시오. localStorage.setItem이 예외를 던질 때 요청이 전송되지 않는 회귀 테스트도 추가하십시오.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/admin/src/lib/api/auth.ts` around lines 21 - 23, Update
saveAdminApiEnvironment to return whether localStorage persistence succeeded,
then update the sign-in flow around saveAdminApiEnvironment in the auth request
to abort before authAxiosInstance.post when saving the resolved environment
fails. Preserve the existing token removal and successful-login request
behavior, and add a regression test confirming localStorage.setItem failures
prevent the request from being sent.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 82f0be5945

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/admin/src/lib/api/auth.ts Outdated
Comment on lines 22 to 23
saveAdminApiEnvironment(resolveEnvironmentFromEmail(email));
return authAxiosInstance.post("/auth/email/sign-in", { email, password });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Route sign-in independently of fallible storage

When localStorage is unavailable (for example, browser storage is disabled), saveAdminApiEnvironment catches and suppresses the write failure, after which the request interceptor reads no stored environment and defaults to production. A @dev.solid-connection.com login therefore sends the credentials to the production API instead of the stage API; the resolved environment should be applied directly to this sign-in request rather than relying on a successful storage round trip.

Useful? React with 👍 / 👎.

CodeRabbit/Codex 리뷰 지적 반영: saveAdminApiEnvironment의 localStorage
쓰기가 실패하면(프라이빗 브라우징 등) 요청 인터셉터가 저장된 환경을 못
읽어 prod로 기본 처리되면서, dev 계정 자격증명이 prod API로 전송될 수
있었다. adminSignInApi가 이번 요청의 baseURL을 직접 지정하도록 해
localStorage 왕복 결과와 무관하게 올바른 환경으로 가도록 수정했다.
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.

1 participant