Skip to content

Commit 977e53c

Browse files
Merge pull request #436 from DevLoversTeam/fix/redis-indent
Fix Netlify runtime env resolution for admin visibility and shop status token
2 parents 6998f02 + 9cc3a53 commit 977e53c

8 files changed

Lines changed: 37 additions & 13 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: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'server-only';
33
import type { NextRequest } from 'next/server';
44

55
import { getCurrentUser } from '@/lib/auth';
6+
import { readServerEnv } from '@/lib/env/server-env';
67

78
export class AdminApiDisabledError extends Error {
89
code = 'ADMIN_API_DISABLED' as const;
@@ -29,10 +30,14 @@ export class AdminForbiddenError extends Error {
2930
}
3031

3132
export function assertAdminApiEnabled(): void {
32-
if (
33-
process.env.NODE_ENV === 'production' &&
34-
process.env.ENABLE_ADMIN_API !== 'true'
35-
) {
33+
const enabled =
34+
(
35+
readServerEnv('ENABLE_ADMIN_API') ??
36+
readServerEnv('NEXT_PUBLIC_ENABLE_ADMIN') ??
37+
''
38+
).toLowerCase() === 'true';
39+
40+
if (process.env.NODE_ENV === 'production' && !enabled) {
3641
throw new AdminApiDisabledError();
3742
}
3843
}

frontend/lib/email/sendPasswordResetEmail.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { readServerEnv } from '@/lib/env/server-env';
2+
13
import { resetPasswordTemplate } from './templates/reset-password';
24
import { mailer } from './transporter';
35

@@ -7,7 +9,7 @@ type Params = {
79
};
810

911
export async function sendPasswordResetEmail({ to, resetUrl }: Params) {
10-
const from = process.env.EMAIL_FROM;
12+
const from = readServerEnv('EMAIL_FROM');
1113

1214
if (!from) {
1315
throw new Error('EMAIL_FROM is not configured');

frontend/lib/email/sendVerificationEmail.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { readServerEnv } from '@/lib/env/server-env';
2+
13
import { verifyEmailTemplate } from './templates/verify-email';
24
import { mailer } from './transporter';
35

@@ -7,7 +9,7 @@ type Params = {
79
};
810

911
export async function sendVerificationEmail({ to, verifyUrl }: Params) {
10-
const from = process.env.EMAIL_FROM;
12+
const from = readServerEnv('EMAIL_FROM');
1113

1214
if (!from) {
1315
throw new Error('EMAIL_FROM is not configured');

frontend/lib/email/transporter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import nodemailer from 'nodemailer';
22

3-
const user = process.env.GMAIL_USER;
4-
const pass = process.env.GMAIL_APP_PASSWORD;
3+
import { readServerEnv } from '@/lib/env/server-env';
4+
5+
const user = readServerEnv('GMAIL_USER');
6+
const pass = readServerEnv('GMAIL_APP_PASSWORD');
57

68
if (!user || !pass) {
79
throw new Error('Missing Gmail SMTP credentials');

frontend/lib/env/server-env.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ 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',
47+
'APP_ORIGIN',
48+
'APP_ADDITIONAL_ORIGINS',
49+
'GMAIL_USER',
50+
'GMAIL_APP_PASSWORD',
51+
'EMAIL_FROM',
4452
]);
4553

4654

frontend/lib/security/origin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { NextRequest, NextResponse } from 'next/server';
22

3+
import { readServerEnv } from '@/lib/env/server-env';
4+
35
const LOCALHOST_ORIGIN = 'http://localhost:3000';
46

57
function buildErrorResponse(
@@ -49,13 +51,13 @@ export function normalizeOrigin(input: string): string {
4951
export function getAllowedOrigins(): string[] {
5052
const allowed = new Set<string>();
5153

52-
const appOrigin = (process.env.APP_ORIGIN ?? '').trim();
54+
const appOrigin = (readServerEnv('APP_ORIGIN') ?? '').trim();
5355
if (appOrigin) {
5456
const normalized = normalizeOrigin(appOrigin);
5557
if (normalized) allowed.add(normalized);
5658
}
5759

58-
const additionalRaw = (process.env.APP_ADDITIONAL_ORIGINS ?? '').trim();
60+
const additionalRaw = (readServerEnv('APP_ADDITIONAL_ORIGINS') ?? '').trim();
5961
if (additionalRaw) {
6062
for (const entry of additionalRaw.split(',')) {
6163
const candidate = entry.trim();

frontend/lib/shop/status-token.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import crypto from 'node:crypto';
22

3+
import { readServerEnv } from '@/lib/env/server-env';
4+
35
export const STATUS_TOKEN_SCOPES = [
46
'status_lite',
57
'order_payment_init',
@@ -27,7 +29,7 @@ type TokenPayload = {
2729
const DEFAULT_TTL_SECONDS = 45 * 60;
2830

2931
function getSecret(): string {
30-
const raw = process.env.SHOP_STATUS_TOKEN_SECRET ?? '';
32+
const raw = readServerEnv('SHOP_STATUS_TOKEN_SECRET') ?? '';
3133
const trimmed = raw.trim();
3234
if (!trimmed) {
3335
throw new Error('SHOP_STATUS_TOKEN_SECRET is not configured');

0 commit comments

Comments
 (0)