Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ yarn-error.log*

# local env files
.env*.local
.env.local

# vercel
.vercel
Expand Down
15 changes: 15 additions & 0 deletions __tests__/config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, it, expect } from 'vitest';
import pool from '../lib/config/postgres';
import authConfig from '../lib/config/auth';

describe('Configuration Setup', () => {
it('should have a valid PostgreSQL connection pool', () => {
expect(pool).toBeDefined();
});

it('should have a valid authentication configuration', () => {
expect(authConfig).toBeDefined();
expect(authConfig.secret).toBeTruthy();
expect(authConfig.tokenExpiration).toBe('7d');
});
});
15 changes: 15 additions & 0 deletions lib/config/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as BetterAuth from 'better-auth';

const authConfig = {
secret: process.env.AUTH_SECRET || 'your_fallback_secret', // IMPORTANT: Use a secure, environment-specific secret
tokenExpiration: '7d',
passwordResetTokenExpiration: '1h',
emailVerificationTokenExpiration: '24h',
passwordHashRounds: 10,
loginAttempts: {
max: 5,
resetTime: 60 * 60 * 1000, // 1 hour
},
};

export default authConfig;
25 changes: 25 additions & 0 deletions lib/config/postgres.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Pool } from 'pg';

const pool = new Pool({
user: process.env.POSTGRES_USER || 'postgres',
host: process.env.POSTGRES_HOST || 'localhost',
database: process.env.POSTGRES_DATABASE || 'jobit_db',
password: process.env.POSTGRES_PASSWORD || '',
port: parseInt(process.env.POSTGRES_PORT || '5432', 10),
ssl: process.env.NODE_ENV === 'production' ? { rejectUnauthorized: false } : false,
});

export const query = async (text: string, params?: any[]) => {
try {
const start = Date.now();
const result = await pool.query(text, params);
const duration = Date.now() - start;
console.log('Executed query', { text, duration, rows: result.rowCount });
return result;
} catch (error) {
console.error('Query error', error);
throw error;
}
};

export default pool;
Loading