fix: enhance error logging by replacing console.error with a centralized logger across the application to improve security and maintainability
This commit is contained in:
@@ -6,6 +6,7 @@ import apiRequest from '@/lib/api/client'
|
||||
import { LoadingOverlay } from '@ciphera-net/ui'
|
||||
import { logoutAction, getSessionAction, setSessionAction } from '@/app/actions/auth'
|
||||
import { getUserOrganizations, switchContext } from '@/lib/api/organization'
|
||||
import { logger } from '@/lib/utils/logger'
|
||||
|
||||
interface User {
|
||||
id: string
|
||||
@@ -66,7 +67,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
return merged
|
||||
})
|
||||
})
|
||||
.catch((e) => console.error('Failed to fetch full profile after login', e))
|
||||
.catch((e) => logger.error('Failed to fetch full profile after login', e))
|
||||
}
|
||||
|
||||
const logout = useCallback(async () => {
|
||||
@@ -96,7 +97,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
return merged
|
||||
})
|
||||
} catch (e) {
|
||||
console.error('Failed to refresh user data', e)
|
||||
logger.error('Failed to refresh user data', e)
|
||||
}
|
||||
router.refresh()
|
||||
}, [router])
|
||||
@@ -121,7 +122,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
setUser(merged)
|
||||
localStorage.setItem('user', JSON.stringify(merged))
|
||||
} catch (e) {
|
||||
console.error('Failed to fetch full profile', e)
|
||||
logger.error('Failed to fetch full profile', e)
|
||||
}
|
||||
} else {
|
||||
// * Session invalid/expired
|
||||
@@ -178,11 +179,11 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
router.refresh()
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to auto-switch context', e)
|
||||
logger.error('Failed to auto-switch context', e)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to fetch organizations", e)
|
||||
logger.error("Failed to fetch organizations", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
lib/utils/logger.ts
Normal file
16
lib/utils/logger.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Dev-only logger that suppresses client-side output in production.
|
||||
* Server-side logs always pass through (they go to server logs, not the browser).
|
||||
*/
|
||||
|
||||
const isServer = typeof window === 'undefined'
|
||||
const isDev = process.env.NODE_ENV === 'development'
|
||||
|
||||
export const logger = {
|
||||
error(...args: unknown[]) {
|
||||
if (isServer || isDev) console.error(...args)
|
||||
},
|
||||
warn(...args: unknown[]) {
|
||||
if (isServer || isDev) console.warn(...args)
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user