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
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Database Configuration
DB_USER=your_database_user
DB_PASSWORD=your_database_password
DB_HOST=localhost
DB_PORT=5432
DB_NAME=jobit_db

# Better Auth Configuration
AUTH_SECRET=your_auth_secret_key
JWT_SECRET=your_jwt_secret_key

# Optional: Additional environment-specific settings
NODE_ENV=development
19 changes: 19 additions & 0 deletions __tests__/dependencies.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, it, expect } from 'vitest';
import { Pool } from 'pg';
import { AuthConfig } from 'better-auth';

describe('Dependencies', () => {
it('should import PostgreSQL pool', () => {
const pool = new Pool();
expect(pool).toBeDefined();
});

it('should import better-auth configuration', () => {
const authConfig: AuthConfig = {
jwtSecret: 'test_secret',
tokenExpiration: '1h',
};
expect(authConfig).toBeDefined();
expect(authConfig.jwtSecret).toBe('test_secret');
});
});
26 changes: 26 additions & 0 deletions config/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { AuthConfig } from 'better-auth';

const authConfig: AuthConfig = {
jwtSecret: process.env.JWT_SECRET || 'fallback_secret_key',
tokenExpiration: '1h', // Token expires in 1 hour
refreshTokenExpiration: '7d', // Refresh token expires in 7 days

// Additional authentication strategies can be configured here
strategies: {
local: {
usernameField: 'email',
passwordField: 'password',
},
},

// Optional: Password complexity requirements
passwordValidation: {
minLength: 8,
requireUppercase: true,
requireLowercase: true,
requireNumbers: true,
requireSpecialChars: true,
},
};

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

// PostgreSQL connection configuration
const pool = new Pool({
user: process.env.DB_USER || 'defaultuser',
host: process.env.DB_HOST || 'localhost',
database: process.env.DB_NAME || 'jobit_db',
password: process.env.DB_PASSWORD || '',
port: parseInt(process.env.DB_PORT || '5432', 10),
});

// Function to get a database client
export const getDbClient = async () => {
try {
const client = await pool.connect();
return client;
} catch (error) {
console.error('Error connecting to the database:', error);
throw error;
}
};

// Function to execute a query
export const executeQuery = async (query: string, params?: any[]) => {
const client = await getDbClient();
try {
const result = await client.query(query, params);
client.release();
return result;
} catch (error) {
client.release();
console.error('Error executing query:', error);
throw error;
}
};
Loading