refactor(logging): replace console usage in auth flows
This commit is contained in:
39
App.tsx
39
App.tsx
@@ -32,6 +32,7 @@ import {
|
||||
AuthPage,
|
||||
AvatarDropdown,
|
||||
ChangePasswordModal,
|
||||
ResetPasswordPage,
|
||||
} from './components/auth';
|
||||
import { AdminInterface } from './components/admin';
|
||||
import {
|
||||
@@ -62,6 +63,8 @@ import {
|
||||
import { useUser } from './contexts/UserContext';
|
||||
import { databaseService } from './services/database';
|
||||
import { databaseSeeder } from './services/database.seeder';
|
||||
import { logger } from './services/logging';
|
||||
import { normalizeError } from './utils/error';
|
||||
|
||||
const Header: React.FC<{
|
||||
onAdd: () => void;
|
||||
@@ -230,7 +233,9 @@ const MedicationScheduleApp: React.FC<{ user: User }> = ({ user }) => {
|
||||
useEffect(() => {
|
||||
// Don't try to fetch data if user._id is not available
|
||||
if (!user._id) {
|
||||
console.warn('Skipping data fetch: user._id is not available');
|
||||
logger.ui.action('Skipping data fetch because user id is missing', {
|
||||
userId: user._id,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -239,7 +244,9 @@ const MedicationScheduleApp: React.FC<{ user: User }> = ({ user }) => {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
console.warn('Fetching data for user:', user._id);
|
||||
logger.db.query('Fetching medication data for user', {
|
||||
userId: user._id,
|
||||
});
|
||||
|
||||
const [medsData, remindersData, takenDosesData, settingsData] =
|
||||
await Promise.all([
|
||||
@@ -249,9 +256,10 @@ const MedicationScheduleApp: React.FC<{ user: User }> = ({ user }) => {
|
||||
databaseService.getUserSettings(user._id),
|
||||
]);
|
||||
|
||||
console.warn('Data fetched successfully:', {
|
||||
medications: medsData.length,
|
||||
reminders: remindersData.length,
|
||||
logger.db.query('Fetched user data successfully', {
|
||||
userId: user._id,
|
||||
medicationCount: medsData.length,
|
||||
reminderCount: remindersData.length,
|
||||
hasTakenDoses: !!takenDosesData,
|
||||
hasSettings: !!settingsData,
|
||||
});
|
||||
@@ -266,8 +274,9 @@ const MedicationScheduleApp: React.FC<{ user: User }> = ({ user }) => {
|
||||
}
|
||||
} catch (e) {
|
||||
setError('Failed to load your data. Please try again.');
|
||||
console.error('Error loading user data:', e);
|
||||
console.error('User object:', user);
|
||||
logger.db.error('Error loading user data', normalizeError(e), {
|
||||
userId: user._id,
|
||||
});
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
@@ -688,7 +697,11 @@ const MedicationScheduleApp: React.FC<{ user: User }> = ({ user }) => {
|
||||
setSettings(updatedSettings);
|
||||
setOnboardingOpen(false);
|
||||
} catch (error) {
|
||||
console.error('Failed to update onboarding status', error);
|
||||
logger.ui.error(
|
||||
'Failed to update onboarding status',
|
||||
normalizeError(error),
|
||||
{ userId: user._id }
|
||||
);
|
||||
setOnboardingOpen(false);
|
||||
}
|
||||
}
|
||||
@@ -910,10 +923,10 @@ const App: React.FC = () => {
|
||||
useEffect(() => {
|
||||
const runSeeding = async () => {
|
||||
try {
|
||||
console.warn('🌱 Initializing database seeding...');
|
||||
logger.db.query('Initializing database seeding');
|
||||
await databaseSeeder.seedDatabase();
|
||||
} catch (error) {
|
||||
console.error('❌ Database seeding failed:', error);
|
||||
logger.db.error('Database seeding failed', normalizeError(error));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -929,6 +942,12 @@ const App: React.FC = () => {
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
if (
|
||||
typeof window !== 'undefined' &&
|
||||
window.location.pathname === '/reset-password'
|
||||
) {
|
||||
return <ResetPasswordPage />;
|
||||
}
|
||||
return <AuthPage />;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user