File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import { ThemeProvider } from '@/components/theme/ThemeProvider';
1313import { getCachedBlogCategories } from '@/db/queries/blog/blog-categories' ;
1414import { AuthProvider } from '@/hooks/useAuth' ;
1515import { locales } from '@/i18n/config' ;
16+ import { readServerEnv } from '@/lib/env/server-env' ;
1617
1718export 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
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import 'server-only';
33import type { NextRequest } from 'next/server' ;
44
55import { getCurrentUser } from '@/lib/auth' ;
6+ import { readServerEnv } from '@/lib/env/server-env' ;
67
78export class AdminApiDisabledError extends Error {
89 code = 'ADMIN_API_DISABLED' as const ;
@@ -29,10 +30,14 @@ export class AdminForbiddenError extends Error {
2930}
3031
3132export 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}
Original file line number Diff line number Diff line change 1+ import { readServerEnv } from '@/lib/env/server-env' ;
2+
13import { resetPasswordTemplate } from './templates/reset-password' ;
24import { mailer } from './transporter' ;
35
@@ -7,7 +9,7 @@ type Params = {
79} ;
810
911export 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' ) ;
Original file line number Diff line number Diff line change 1+ import { readServerEnv } from '@/lib/env/server-env' ;
2+
13import { verifyEmailTemplate } from './templates/verify-email' ;
24import { mailer } from './transporter' ;
35
@@ -7,7 +9,7 @@ type Params = {
79} ;
810
911export 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' ) ;
Original file line number Diff line number Diff line change 11import 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
68if ( ! user || ! pass ) {
79 throw new Error ( 'Missing Gmail SMTP credentials' ) ;
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 11import { NextRequest , NextResponse } from 'next/server' ;
22
3+ import { readServerEnv } from '@/lib/env/server-env' ;
4+
35const LOCALHOST_ORIGIN = 'http://localhost:3000' ;
46
57function buildErrorResponse (
@@ -49,13 +51,13 @@ export function normalizeOrigin(input: string): string {
4951export 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 ( ) ;
Original file line number Diff line number Diff line change 11import crypto from 'node:crypto' ;
22
3+ import { readServerEnv } from '@/lib/env/server-env' ;
4+
35export const STATUS_TOKEN_SCOPES = [
46 'status_lite' ,
57 'order_payment_init' ,
@@ -27,7 +29,7 @@ type TokenPayload = {
2729const DEFAULT_TTL_SECONDS = 45 * 60 ;
2830
2931function 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' ) ;
You can’t perform that action at this time.
0 commit comments