Fix Netlify runtime env resolution for admin visibility and shop status token#436
Fix Netlify runtime env resolution for admin visibility and shop status token#436liudmylasovetovs merged 2 commits intodevelopfrom
Conversation
- switch admin feature flag resolution in locale layout to readServerEnv - update admin guard to use readServerEnv(ENABLE_ADMIN_API) - update shop status token secret read to readServerEnv - extend generated runtime fallback allowlist with: ENABLE_ADMIN_API, NEXT_PUBLIC_ENABLE_ADMIN, SHOP_STATUS_TOKEN_SECRET - preserve Vercel-safe runtime-env.generated.ts stub import flow
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRefactors server-side configuration reads to use the centralized Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@frontend/lib/auth/admin.ts`:
- Line 35: The admin-flag parsing is inconsistent: assertAdminApiEnabled()
checks for exact 'true' while the layout path lowercases before comparing,
causing values like 'TRUE' to pass UI but fail the guard; fix by normalizing the
env value in one place and using it everywhere (e.g., add a helper like
isAdminApiEnabled() that calls readServerEnv('ENABLE_ADMIN_API'),
lowercases/trims the result and compares to 'true'), then update
assertAdminApiEnabled() and the layout check to call that helper so both UI and
guard use the same normalized logic.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2e80d2eb-5dab-4208-ac51-5cd2503685b6
📒 Files selected for processing (4)
frontend/app/[locale]/layout.tsxfrontend/lib/auth/admin.tsfrontend/lib/env/server-env.tsfrontend/lib/shop/status-token.ts
What
This PR fixes remaining runtime env reads that could fail in Netlify SSR/functions when
process.envis partially unavailable at runtime.Changes
frontend/app/[locale]/layout.tsxprocess.envreads for admin flag withreadServerEnv(...)frontend/lib/auth/admin.tsassertAdminApiEnabled()now usesreadServerEnv('ENABLE_ADMIN_API')frontend/lib/shop/status-token.tsSHOP_STATUS_TOKEN_SECRETnow resolved viareadServerEnv(...)frontend/lib/env/server-env.tsENABLE_ADMIN_APINEXT_PUBLIC_ENABLE_ADMINSHOP_STATUS_TOKEN_SECRETWhy
We already migrated DB/auth/redis paths to runtime-safe env resolution.
These remaining direct reads could still disable admin features or break status-token flows in Netlify runtime despite correct env values in project settings.
Expected result
process.envavailability.process.envremains first priority).Validation
readServerEnvis used in all updated paths.Summary by CodeRabbit