mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-22 06:28:19 +02:00
Refine debug logging for development and production environments
Update console logs to only display in development mode and improve error handling logic for production authentication and reconciliation processes. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 1e4433b5-47ab-464c-b663-fea2e53367dd Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/1e4433b5-47ab-464c-b663-fea2e53367dd/zhCtuJP
This commit is contained in:
1 parent
b51f1ace40
commit
2a23e0da4d
5 files changed
+136
-64
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 209 KiB |
@@ -28,19 +28,21 @@ import Layout from "@/components/Layout";
|
|||||||
function RouterProduction() {
|
function RouterProduction() {
|
||||||
const { isAuthenticated, isLoading, user, environment, error } = useAuthUnified();
|
const { isAuthenticated, isLoading, user, environment, error } = useAuthUnified();
|
||||||
|
|
||||||
// Debug complet pour la production
|
// Debug uniquement en développement
|
||||||
console.log('🔍 RouterProduction Debug:', {
|
if (import.meta.env.DEV) {
|
||||||
environment,
|
console.log('🔍 RouterProduction Debug:', {
|
||||||
isAuthenticated,
|
environment,
|
||||||
isLoading,
|
isAuthenticated,
|
||||||
hasUser: !!user,
|
isLoading,
|
||||||
userId: user?.id,
|
hasUser: !!user,
|
||||||
username: user?.username,
|
userId: user?.id,
|
||||||
error: error?.message
|
username: user?.username,
|
||||||
});
|
error: error?.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Debug minimal basé sur l'environnement
|
// Debug minimal basé sur l'environnement
|
||||||
if (environment === 'production' && error) {
|
if (environment === 'production' && error && import.meta.env.DEV) {
|
||||||
console.error('🚨 Production Auth Error:', error);
|
console.error('🚨 Production Auth Error:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +60,9 @@ function RouterProduction() {
|
|||||||
if (!isAuthenticated) {
|
if (!isAuthenticated) {
|
||||||
// Redirection automatique vers la page d'authentification
|
// Redirection automatique vers la page d'authentification
|
||||||
if (typeof window !== 'undefined' && window.location.pathname !== '/auth') {
|
if (typeof window !== 'undefined' && window.location.pathname !== '/auth') {
|
||||||
console.log('🔄 User not authenticated, redirecting to auth page');
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 User not authenticated, redirecting to auth page');
|
||||||
|
}
|
||||||
window.location.href = '/auth';
|
window.location.href = '/auth';
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen w-full flex items-center justify-center bg-surface">
|
<div className="min-h-screen w-full flex items-center justify-center bg-surface">
|
||||||
@@ -109,7 +113,9 @@ function RouterProduction() {
|
|||||||
<Route path="/auth">
|
<Route path="/auth">
|
||||||
{() => {
|
{() => {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
console.log('🔄 Authenticated user on /auth, redirecting to dashboard');
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 Authenticated user on /auth, redirecting to dashboard');
|
||||||
|
}
|
||||||
window.location.href = '/';
|
window.location.href = '/';
|
||||||
}
|
}
|
||||||
return <Dashboard />;
|
return <Dashboard />;
|
||||||
|
|||||||
@@ -10,12 +10,14 @@ export function useAuthUnified() {
|
|||||||
window.location.hostname.includes('replit.dev')) &&
|
window.location.hostname.includes('replit.dev')) &&
|
||||||
import.meta.env.DEV === true;
|
import.meta.env.DEV === true;
|
||||||
|
|
||||||
// Debug logging pour comprendre l'environnement
|
// Debug logging uniquement en développement
|
||||||
console.log('🔍 Auth Environment Debug:', {
|
if (import.meta.env.DEV) {
|
||||||
hostname: typeof window !== 'undefined' ? window.location.hostname : 'N/A',
|
console.log('🔍 Auth Environment Debug:', {
|
||||||
isDev: import.meta.env.DEV,
|
hostname: typeof window !== 'undefined' ? window.location.hostname : 'N/A',
|
||||||
environment: isDevelopment ? 'development' : 'production'
|
isDev: import.meta.env.DEV,
|
||||||
});
|
environment: isDevelopment ? 'development' : 'production'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// État pour la version production (fetch direct)
|
// État pour la version production (fetch direct)
|
||||||
const [productionUser, setProductionUser] = useState<any>(null);
|
const [productionUser, setProductionUser] = useState<any>(null);
|
||||||
@@ -43,28 +45,40 @@ export function useAuthUnified() {
|
|||||||
|
|
||||||
// Fonction pour rafraîchir l'authentification
|
// Fonction pour rafraîchir l'authentification
|
||||||
const refreshAuth = () => {
|
const refreshAuth = () => {
|
||||||
console.log('🔄 RefreshAuth called, isDevelopment:', isDevelopment);
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 RefreshAuth called, isDevelopment:', isDevelopment);
|
||||||
|
}
|
||||||
if (!isDevelopment) {
|
if (!isDevelopment) {
|
||||||
console.log('🔄 Triggering production auth refresh');
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 Triggering production auth refresh');
|
||||||
|
}
|
||||||
setRefreshTrigger(prev => {
|
setRefreshTrigger(prev => {
|
||||||
const newValue = prev + 1;
|
const newValue = prev + 1;
|
||||||
console.log('🔄 Production refresh trigger updated:', prev, '->', newValue);
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 Production refresh trigger updated:', prev, '->', newValue);
|
||||||
|
}
|
||||||
return newValue;
|
return newValue;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log('🔄 Development mode - using React Query refresh');
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 Development mode - using React Query refresh');
|
||||||
|
}
|
||||||
developmentQuery.refetch();
|
developmentQuery.refetch();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fonction pour rafraîchir de manière synchrone (pour après login)
|
// Fonction pour rafraîchir de manière synchrone (pour après login)
|
||||||
const forceAuthRefresh = async () => {
|
const forceAuthRefresh = async () => {
|
||||||
console.log('🔄 ForceAuthRefresh called, isDevelopment:', isDevelopment);
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 ForceAuthRefresh called, isDevelopment:', isDevelopment);
|
||||||
|
}
|
||||||
|
|
||||||
if (!isDevelopment) {
|
if (!isDevelopment) {
|
||||||
// En production, faire un fetch immédiat et forcer un re-render
|
// En production, faire un fetch immédiat et forcer un re-render
|
||||||
try {
|
try {
|
||||||
console.log('🔄 Production force refresh - fetching user data');
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 Production force refresh - fetching user data');
|
||||||
|
}
|
||||||
setProductionLoading(true);
|
setProductionLoading(true);
|
||||||
|
|
||||||
const response = await fetch('/api/user', {
|
const response = await fetch('/api/user', {
|
||||||
@@ -78,7 +92,9 @@ export function useAuthUnified() {
|
|||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const userData = await response.json();
|
const userData = await response.json();
|
||||||
console.log('✅ Production force refresh success:', { username: userData?.username, id: userData?.id });
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('✅ Production force refresh success:', { username: userData?.username, id: userData?.id });
|
||||||
|
}
|
||||||
setProductionUser(userData);
|
setProductionUser(userData);
|
||||||
setProductionError(null);
|
setProductionError(null);
|
||||||
setProductionLoading(false);
|
setProductionLoading(false);
|
||||||
@@ -88,14 +104,18 @@ export function useAuthUnified() {
|
|||||||
|
|
||||||
return userData;
|
return userData;
|
||||||
} else {
|
} else {
|
||||||
console.log('❌ Production force refresh failed:', response.status);
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('❌ Production force refresh failed:', response.status);
|
||||||
|
}
|
||||||
setProductionUser(null);
|
setProductionUser(null);
|
||||||
setProductionError(null);
|
setProductionError(null);
|
||||||
setProductionLoading(false);
|
setProductionLoading(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ Production force refresh error:', error);
|
if (import.meta.env.DEV) {
|
||||||
|
console.error('❌ Production force refresh error:', error);
|
||||||
|
}
|
||||||
setProductionError(error);
|
setProductionError(error);
|
||||||
setProductionUser(null);
|
setProductionUser(null);
|
||||||
setProductionLoading(false);
|
setProductionLoading(false);
|
||||||
@@ -103,7 +123,9 @@ export function useAuthUnified() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// En développement, forcer un refetch avec invalidation du cache
|
// En développement, forcer un refetch avec invalidation du cache
|
||||||
console.log('🔄 Development mode - invalidating cache and refetching');
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 Development mode - invalidating cache and refetching');
|
||||||
|
}
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
queryClient.invalidateQueries({ queryKey: ['/api/user'] });
|
queryClient.invalidateQueries({ queryKey: ['/api/user'] });
|
||||||
|
|
||||||
@@ -111,11 +133,13 @@ export function useAuthUnified() {
|
|||||||
await new Promise(resolve => setTimeout(resolve, 50));
|
await new Promise(resolve => setTimeout(resolve, 50));
|
||||||
|
|
||||||
const result = await developmentQuery.refetch();
|
const result = await developmentQuery.refetch();
|
||||||
console.log('🔄 Development refetch result:', {
|
if (import.meta.env.DEV) {
|
||||||
success: result.isSuccess,
|
console.log('🔄 Development refetch result:', {
|
||||||
hasData: !!result.data,
|
success: result.isSuccess,
|
||||||
userId: result.data?.id
|
hasData: !!result.data,
|
||||||
});
|
userId: result.data?.id
|
||||||
|
});
|
||||||
|
}
|
||||||
return result.data;
|
return result.data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -128,7 +152,9 @@ export function useAuthUnified() {
|
|||||||
|
|
||||||
const checkAuth = async () => {
|
const checkAuth = async () => {
|
||||||
try {
|
try {
|
||||||
console.log('🔄 Production auth check starting, refreshTrigger:', refreshTrigger);
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 Production auth check starting, refreshTrigger:', refreshTrigger);
|
||||||
|
}
|
||||||
setProductionLoading(true);
|
setProductionLoading(true);
|
||||||
|
|
||||||
const response = await fetch('/api/user', {
|
const response = await fetch('/api/user', {
|
||||||
@@ -140,19 +166,25 @@ export function useAuthUnified() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('🔄 Production auth response:', response.status);
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 Production auth response:', response.status);
|
||||||
|
}
|
||||||
|
|
||||||
if (!isMounted) return;
|
if (!isMounted) return;
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const userData = await response.json();
|
const userData = await response.json();
|
||||||
console.log('✅ Production auth success:', { username: userData?.username, id: userData?.id });
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('✅ Production auth success:', { username: userData?.username, id: userData?.id });
|
||||||
|
}
|
||||||
if (isMounted) {
|
if (isMounted) {
|
||||||
setProductionUser(userData);
|
setProductionUser(userData);
|
||||||
setProductionError(null);
|
setProductionError(null);
|
||||||
}
|
}
|
||||||
} else if (response.status === 401) {
|
} else if (response.status === 401) {
|
||||||
console.log('❌ Production auth 401 - user not authenticated');
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('❌ Production auth 401 - user not authenticated');
|
||||||
|
}
|
||||||
if (isMounted) {
|
if (isMounted) {
|
||||||
setProductionUser(null);
|
setProductionUser(null);
|
||||||
setProductionError(null);
|
setProductionError(null);
|
||||||
@@ -161,14 +193,18 @@ export function useAuthUnified() {
|
|||||||
throw new Error(`Auth failed: ${response.status}`);
|
throw new Error(`Auth failed: ${response.status}`);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Production auth error:', err);
|
if (import.meta.env.DEV) {
|
||||||
|
console.error('Production auth error:', err);
|
||||||
|
}
|
||||||
if (isMounted) {
|
if (isMounted) {
|
||||||
setProductionError(err);
|
setProductionError(err);
|
||||||
setProductionUser(null);
|
setProductionUser(null);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (isMounted) {
|
if (isMounted) {
|
||||||
console.log('🔄 Production auth check complete, loading set to false');
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 Production auth check complete, loading set to false');
|
||||||
|
}
|
||||||
setProductionLoading(false);
|
setProductionLoading(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,9 @@ export default function AuthPage() {
|
|||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
onSuccess: async (loginResult) => {
|
onSuccess: async (loginResult) => {
|
||||||
console.log('✅ Login successful, refreshing auth state...');
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('✅ Login successful, refreshing auth state...');
|
||||||
|
}
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: "Connexion réussie",
|
title: "Connexion réussie",
|
||||||
@@ -108,10 +110,14 @@ export default function AuthPage() {
|
|||||||
|
|
||||||
// Force immediate authentication state refresh
|
// Force immediate authentication state refresh
|
||||||
const refreshedUserData = await forceAuthRefresh();
|
const refreshedUserData = await forceAuthRefresh();
|
||||||
console.log('🔄 Force auth refresh result:', refreshedUserData);
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 Force auth refresh result:', refreshedUserData);
|
||||||
|
}
|
||||||
|
|
||||||
if (refreshedUserData && refreshedUserData.id) {
|
if (refreshedUserData && refreshedUserData.id) {
|
||||||
console.log('🔄 User data confirmed, forcing redirect...');
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 User data confirmed, forcing redirect...');
|
||||||
|
}
|
||||||
setLocation("/");
|
setLocation("/");
|
||||||
} else {
|
} else {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -133,12 +139,14 @@ export default function AuthPage() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Debug logging for authentication state
|
// Debug logging for authentication state
|
||||||
console.log('🔍 AuthPage Debug:', {
|
if (import.meta.env.DEV) {
|
||||||
isAuthenticated,
|
console.log('🔍 AuthPage Debug:', {
|
||||||
isLoading,
|
isAuthenticated,
|
||||||
userId: user?.id,
|
isLoading,
|
||||||
username: user?.username
|
userId: user?.id,
|
||||||
});
|
username: user?.username
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (defaultCredentialsCheck) {
|
if (defaultCredentialsCheck) {
|
||||||
@@ -149,7 +157,9 @@ export default function AuthPage() {
|
|||||||
// Redirect if already authenticated
|
// Redirect if already authenticated
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isLoading && isAuthenticated && user) {
|
if (!isLoading && isAuthenticated && user) {
|
||||||
console.log('🔄 User authenticated, redirecting to dashboard...', { user: user.username, authenticated: isAuthenticated });
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('🔄 User authenticated, redirecting to dashboard...', { user: user.username, authenticated: isAuthenticated });
|
||||||
|
}
|
||||||
// Force immediate redirect to home page
|
// Force immediate redirect to home page
|
||||||
setLocation("/");
|
setLocation("/");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -628,23 +628,24 @@ export default function BLReconciliation() {
|
|||||||
|
|
||||||
// Filtrage des livraisons par recherche et statut de validation
|
// Filtrage des livraisons par recherche et statut de validation
|
||||||
const filterDeliveries = (deliveries: any[]) => {
|
const filterDeliveries = (deliveries: any[]) => {
|
||||||
// Debug temporaire pour production
|
// Debug temporaire pour identifier le problème
|
||||||
if (deliveries.length > 0 && filterStatus !== "all") {
|
if (deliveries.length > 0 && filterStatus !== "all") {
|
||||||
console.log('🔍 DEBUG Filtre Production:', {
|
console.log('🔍 DEBUG Filtre:', {
|
||||||
filterStatus,
|
filterStatus,
|
||||||
totalDeliveries: deliveries.length,
|
totalDeliveries: deliveries.length,
|
||||||
firstDelivery: {
|
exemples: deliveries.slice(0, 3).map(d => ({
|
||||||
id: deliveries[0].id,
|
id: d.id,
|
||||||
reconciled: deliveries[0].reconciled,
|
reconciled: d.reconciled,
|
||||||
type: typeof deliveries[0].reconciled,
|
type: typeof d.reconciled,
|
||||||
rawValue: JSON.stringify(deliveries[0].reconciled)
|
rawValue: JSON.stringify(d.reconciled),
|
||||||
}
|
supplier: d.supplier?.name
|
||||||
|
}))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return deliveries.filter((delivery: any) => {
|
return deliveries.filter((delivery: any) => {
|
||||||
// Conversion sûre de reconciled - gestion de tous les cas possibles
|
// Conversion sûre de reconciled - gestion de tous les cas possibles
|
||||||
// PostgreSQL peut retourner : true/false, 1/0, "t"/"f", "true"/"false"
|
// PostgreSQL peut retourner : true/false, 1/0, "t"/"f", "true"/"false", null, undefined
|
||||||
const isReconciled =
|
const isReconciled =
|
||||||
delivery.reconciled === true ||
|
delivery.reconciled === true ||
|
||||||
delivery.reconciled === 1 ||
|
delivery.reconciled === 1 ||
|
||||||
@@ -652,12 +653,31 @@ export default function BLReconciliation() {
|
|||||||
delivery.reconciled === "true" ||
|
delivery.reconciled === "true" ||
|
||||||
(typeof delivery.reconciled === 'string' && delivery.reconciled.toLowerCase() === 'true');
|
(typeof delivery.reconciled === 'string' && delivery.reconciled.toLowerCase() === 'true');
|
||||||
|
|
||||||
// Filtre par statut validé
|
// Filtre par statut validé - avec debug pour chaque élément filtré
|
||||||
if (filterStatus === "validated" && !isReconciled) {
|
if (filterStatus === "validated") {
|
||||||
return false;
|
const keep = isReconciled;
|
||||||
|
if (!keep && delivery.blNumber) {
|
||||||
|
console.log(`❌ Filtré (non validé):`, {
|
||||||
|
id: delivery.id,
|
||||||
|
bl: delivery.blNumber,
|
||||||
|
reconciled: delivery.reconciled,
|
||||||
|
isReconciled
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return keep;
|
||||||
}
|
}
|
||||||
if (filterStatus === "not_validated" && isReconciled) {
|
|
||||||
return false;
|
if (filterStatus === "not_validated") {
|
||||||
|
const keep = !isReconciled;
|
||||||
|
if (!keep && delivery.blNumber) {
|
||||||
|
console.log(`❌ Filtré (validé):`, {
|
||||||
|
id: delivery.id,
|
||||||
|
bl: delivery.blNumber,
|
||||||
|
reconciled: delivery.reconciled,
|
||||||
|
isReconciled
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return keep;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filtre par recherche
|
// Filtre par recherche
|
||||||
|
|||||||
Reference in new issue
Block a user