Skip to content

Commit c14a6a6

Browse files
committed
fix(env): read critical runtime flags via readServerEnv for Netlify SSR
- 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
1 parent c262b72 commit c14a6a6

4 files changed

Lines changed: 10 additions & 4 deletions

File tree

frontend/app/[locale]/layout.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ThemeProvider } from '@/components/theme/ThemeProvider';
1313
import { getCachedBlogCategories } from '@/db/queries/blog/blog-categories';
1414
import { AuthProvider } from '@/hooks/useAuth';
1515
import { locales } from '@/i18n/config';
16+
import { readServerEnv } from '@/lib/env/server-env';
1617

1718
export default async function LocaleLayout({
1819
children,
@@ -32,8 +33,8 @@ export default async function LocaleLayout({
3233

3334
const enableAdmin =
3435
(
35-
process.env.ENABLE_ADMIN_API ??
36-
process.env.NEXT_PUBLIC_ENABLE_ADMIN ??
36+
readServerEnv('ENABLE_ADMIN_API') ??
37+
readServerEnv('NEXT_PUBLIC_ENABLE_ADMIN') ??
3738
''
3839
).toLowerCase() === 'true';
3940

frontend/lib/auth/admin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'server-only';
22

33
import type { NextRequest } from 'next/server';
4+
import { readServerEnv } from '@/lib/env/server-env';
45

56
import { getCurrentUser } from '@/lib/auth';
67

@@ -31,7 +32,7 @@ export class AdminForbiddenError extends Error {
3132
export function assertAdminApiEnabled(): void {
3233
if (
3334
process.env.NODE_ENV === 'production' &&
34-
process.env.ENABLE_ADMIN_API !== 'true'
35+
readServerEnv('ENABLE_ADMIN_API') !== 'true'
3536
) {
3637
throw new AdminApiDisabledError();
3738
}

frontend/lib/env/server-env.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ const GENERATED_FALLBACK_KEYS = new Set([
4141
'GITHUB_CLIENT_ID_DEVELOP',
4242
'GITHUB_CLIENT_SECRET_DEVELOP',
4343
'GITHUB_CLIENT_REDIRECT_URI_DEVELOP',
44+
'ENABLE_ADMIN_API',
45+
'NEXT_PUBLIC_ENABLE_ADMIN',
46+
'SHOP_STATUS_TOKEN_SECRET',
4447
]);
4548

4649

frontend/lib/shop/status-token.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import crypto from 'node:crypto';
2+
import { readServerEnv } from '@/lib/env/server-env';
23

34
export const STATUS_TOKEN_SCOPES = [
45
'status_lite',
@@ -27,7 +28,7 @@ type TokenPayload = {
2728
const DEFAULT_TTL_SECONDS = 45 * 60;
2829

2930
function getSecret(): string {
30-
const raw = process.env.SHOP_STATUS_TOKEN_SECRET ?? '';
31+
const raw = readServerEnv('SHOP_STATUS_TOKEN_SECRET') ?? '';
3132
const trimmed = raw.trim();
3233
if (!trimmed) {
3334
throw new Error('SHOP_STATUS_TOKEN_SECRET is not configured');

0 commit comments

Comments
 (0)