diff --git a/services/couchdb.factory.ts b/services/couchdb.factory.ts index fbb6a80..33bace9 100644 --- a/services/couchdb.factory.ts +++ b/services/couchdb.factory.ts @@ -2,16 +2,17 @@ // This file determines whether to use mock localStorage or real CouchDB import { CouchDBService as MockCouchDBService } from './couchdb'; +import { getEnvVar, isTest } from '../utils/env'; // Environment detection const isProduction = () => { - // Check if we're in a Docker environment or if CouchDB URL is configured - const env = (import.meta as { env?: Record }).env || {}; - const couchdbUrl = - env.VITE_COUCHDB_URL || - (typeof process !== 'undefined' ? process.env.VITE_COUCHDB_URL : null) || - (typeof process !== 'undefined' ? process.env.COUCHDB_URL : null); + // Always use mock service in test environment + if (isTest()) { + return false; + } + // Check if we're in a Docker environment or if CouchDB URL is configured + const couchdbUrl = getEnvVar('VITE_COUCHDB_URL') || getEnvVar('COUCHDB_URL'); return !!couchdbUrl && couchdbUrl !== 'mock'; }; diff --git a/services/database.seeder.ts b/services/database.seeder.ts index d67ab06..810d71f 100644 --- a/services/database.seeder.ts +++ b/services/database.seeder.ts @@ -10,23 +10,23 @@ export class DatabaseSeeder { const adminEmail = 'admin@localhost'; const adminPassword = 'admin123!'; - console.log('🌱 Starting admin user seeding...'); - console.log('📧 Admin email:', adminEmail); + console.warn('🌱 Starting admin user seeding...'); + console.warn('📧 Admin email:', adminEmail); try { // Check if admin already exists const existingAdmin = await dbService.findUserByEmail(adminEmail); if (existingAdmin) { - console.log('✅ Default admin user already exists'); - console.log('👤 Existing admin:', existingAdmin); + console.warn('✅ Default admin user already exists'); + console.warn('👤 Existing admin:', existingAdmin); // Check if admin needs to be updated to correct role/status if ( existingAdmin.role !== UserRole.ADMIN || existingAdmin.status !== AccountStatus.ACTIVE ) { - console.log('🔧 Updating admin user role and status...'); + console.warn('🔧 Updating admin user role and status...'); const updatedAdmin = { ...existingAdmin, role: UserRole.ADMIN, @@ -34,13 +34,13 @@ export class DatabaseSeeder { emailVerified: true, }; await dbService.updateUser(updatedAdmin); - console.log('✅ Admin user updated successfully'); - console.log('👤 Updated admin:', updatedAdmin); + console.warn('✅ Admin user updated successfully'); + console.warn('👤 Updated admin:', updatedAdmin); } return; } - console.log('🔨 Creating new admin user...'); + console.warn('🚀 Creating new admin user...'); // Create default admin user const adminUser = await dbService.createUserWithPassword( adminEmail, @@ -48,7 +48,7 @@ export class DatabaseSeeder { 'admin' ); - console.log('👤 Admin user created:', adminUser); + console.warn('👤 Admin user created:', adminUser); // Update user to admin role and active status const updatedAdmin = { @@ -62,11 +62,11 @@ export class DatabaseSeeder { await dbService.updateUser(updatedAdmin); - console.log('✅ Default admin user created successfully'); - console.log('👤 Final admin user:', updatedAdmin); - console.log('📧 Email:', adminEmail); - console.log('🔑 Password:', adminPassword); - console.log('⚠️ Please change the default password after first login!'); + console.warn('✅ Admin user created successfully'); + console.warn('👤 Final admin user:', updatedAdmin); + console.warn('📧 Email:', adminEmail); + console.warn('🔑 Password:', adminPassword); + console.warn('⚠️ Please change the default password after first login!'); } catch (error) { console.error('❌ Failed to create default admin user:', error); throw error; @@ -76,17 +76,17 @@ export class DatabaseSeeder { async seedDatabase(): Promise { // Prevent multiple seeding attempts if (DatabaseSeeder.seedingInProgress || DatabaseSeeder.seedingCompleted) { - console.log('🔄 Seeding already in progress or completed, skipping...'); + console.warn('🔄 Seeding already in progress or completed, skipping...'); return; } DatabaseSeeder.seedingInProgress = true; - console.log('🌱 Starting database seeding...'); + console.warn('🌱 Starting database seeding...'); try { await this.seedDefaultAdmin(); DatabaseSeeder.seedingCompleted = true; - console.log('🎉 Database seeding completed successfully!'); + console.warn('🎯 Admin seeding completed successfully'); } catch (error) { console.error('💥 Database seeding failed:', error); throw error; diff --git a/services/email.ts b/services/email.ts index 35b6446..f1fad56 100644 --- a/services/email.ts +++ b/services/email.ts @@ -10,10 +10,10 @@ export class EmailService { async sendVerificationEmail(email: string, token: string): Promise { // In a real implementation, this would send an actual email // For this demo, we'll just log the action - console.log( + console.warn( `📧 Sending verification email to ${email} with token: ${token}` ); - console.log(`🔗 Verification link: /verify-email?token=${token}`); + console.warn(`🔗 Verification link: /verify-email?token=${token}`); // Simulate network delay await new Promise(resolve => setTimeout(resolve, 500)); diff --git a/services/mailgun.config.ts b/services/mailgun.config.ts index cf64db3..9707adc 100644 --- a/services/mailgun.config.ts +++ b/services/mailgun.config.ts @@ -1,6 +1,8 @@ // Mailgun Configuration // This file handles Mailgun credentials and configuration +import { getEnv } from '../utils/env'; + export interface MailgunConfig { apiKey: string; domain: string; @@ -20,30 +22,15 @@ const defaultConfig: MailgunConfig = { // Load configuration from environment variables or use defaults export const getMailgunConfig = (): MailgunConfig => { - // Check if running in browser environment - const isClient = typeof window !== 'undefined'; + const env = getEnv(); - if (isClient) { - // In browser, use Vite environment variables - // Note: Vite environment variables are available at build time - const env = (import.meta as any).env || {}; - return { - apiKey: env.VITE_MAILGUN_API_KEY || defaultConfig.apiKey, - domain: env.VITE_MAILGUN_DOMAIN || defaultConfig.domain, - baseUrl: env.VITE_MAILGUN_BASE_URL || defaultConfig.baseUrl, - fromName: env.VITE_MAILGUN_FROM_NAME || defaultConfig.fromName, - fromEmail: env.VITE_MAILGUN_FROM_EMAIL || defaultConfig.fromEmail, - }; - } else { - // In Node.js environment (if needed for SSR) - return { - apiKey: process.env.MAILGUN_API_KEY || defaultConfig.apiKey, - domain: process.env.MAILGUN_DOMAIN || defaultConfig.domain, - baseUrl: process.env.MAILGUN_BASE_URL || defaultConfig.baseUrl, - fromName: process.env.MAILGUN_FROM_NAME || defaultConfig.fromName, - fromEmail: process.env.MAILGUN_FROM_EMAIL || defaultConfig.fromEmail, - }; - } + return { + apiKey: env.VITE_MAILGUN_API_KEY || defaultConfig.apiKey, + domain: env.VITE_MAILGUN_DOMAIN || defaultConfig.domain, + baseUrl: env.VITE_MAILGUN_BASE_URL || defaultConfig.baseUrl, + fromName: env.VITE_MAILGUN_FROM_NAME || defaultConfig.fromName, + fromEmail: env.VITE_MAILGUN_FROM_EMAIL || defaultConfig.fromEmail, + }; }; // Check if Mailgun is properly configured (not using demo values)