Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { cookies } from 'next/headers';

import { db } from '@/db';
import { users } from '@/db/schema/users';
import { readServerEnv } from '@/lib/env/server-env';

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

const _AUTH_SECRET = process.env.AUTH_SECRET;
const _AUTH_SECRET = readServerEnv('AUTH_SECRET');

if (!_AUTH_SECRET) {
throw new Error('AUTH_SECRET is not defined');
Expand Down
4 changes: 3 additions & 1 deletion frontend/lib/security/csrf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import crypto from 'node:crypto';

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

import { readServerEnv } from '@/lib/env/server-env';

export const CSRF_FORM_FIELD = 'csrfToken' as const;

const DEFAULT_TTL_SECONDS = 60 * 60;
function getSecret(): string {
const secret = process.env.CSRF_SECRET;
const secret = readServerEnv('CSRF_SECRET');
if (!secret) throw new Error('Missing env var: CSRF_SECRET');
return secret;
}
Expand Down
Loading