Skip to content

Commit 10d2e45

Browse files
Merge pull request #432 from DevLoversTeam/sl/feat/db-optimization
fix(netlify-env): stabilize auth/csrf secrets in SSR runtime via readServerEnv
2 parents 1ee6d1e + 99abec9 commit 10d2e45

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

frontend/lib/auth.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { cookies } from 'next/headers';
66

77
import { db } from '@/db';
88
import { users } from '@/db/schema/users';
9+
import { readServerEnv } from '@/lib/env/server-env';
910

1011
const AUTH_COOKIE_NAME = 'auth_session';
1112
const AUTH_TOKEN_MAX_AGE = 60 * 60 * 24 * 7; // 7 days
1213

13-
const _AUTH_SECRET = process.env.AUTH_SECRET;
14+
const _AUTH_SECRET = readServerEnv('AUTH_SECRET');
1415

1516
if (!_AUTH_SECRET) {
1617
throw new Error('AUTH_SECRET is not defined');

frontend/lib/security/csrf.ts

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

55
import type { NextRequest } from 'next/server';
66

7+
import { readServerEnv } from '@/lib/env/server-env';
8+
79
export const CSRF_FORM_FIELD = 'csrfToken' as const;
810

911
const DEFAULT_TTL_SECONDS = 60 * 60;
1012
function getSecret(): string {
11-
const secret = process.env.CSRF_SECRET;
13+
const secret = readServerEnv('CSRF_SECRET');
1214
if (!secret) throw new Error('Missing env var: CSRF_SECRET');
1315
return secret;
1416
}

0 commit comments

Comments
 (0)