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:
@@ -1,6 +1,7 @@
|
||||
'use server'
|
||||
|
||||
import { cookies } from 'next/headers'
|
||||
import { logger } from '@/lib/utils/logger'
|
||||
|
||||
const AUTH_API_URL = process.env.NEXT_PUBLIC_AUTH_API_URL || process.env.NEXT_PUBLIC_AUTH_URL || 'http://localhost:8081'
|
||||
|
||||
@@ -102,7 +103,7 @@ export async function exchangeAuthCode(code: string, codeVerifier: string, redir
|
||||
}
|
||||
|
||||
} catch (error: unknown) {
|
||||
console.error('Auth Exchange Error:', error)
|
||||
logger.error('Auth Exchange Error:', error)
|
||||
const isNetwork =
|
||||
error instanceof TypeError ||
|
||||
(error instanceof Error && (error.name === 'AbortError' || /fetch|network|ECONNREFUSED|ETIMEDOUT/i.test(error.message)))
|
||||
@@ -152,7 +153,7 @@ export async function setSessionAction(accessToken: string, refreshToken?: strin
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[setSessionAction] Error:', e)
|
||||
logger.error('[setSessionAction] Error:', e)
|
||||
return { success: false as const, error: 'invalid' }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState, Suspense, useRef, useCallback } from 'react'
|
||||
import { logger } from '@/lib/utils/logger'
|
||||
import { useRouter, useSearchParams } from 'next/navigation'
|
||||
import { useAuth } from '@/lib/auth/context'
|
||||
import { AUTH_URL, default as apiRequest } from '@/lib/api/client'
|
||||
@@ -96,7 +97,7 @@ function AuthCallbackContent() {
|
||||
return
|
||||
}
|
||||
if (state !== storedState) {
|
||||
console.error('State mismatch', { received: state, stored: storedState })
|
||||
logger.error('State mismatch', { received: state, stored: storedState })
|
||||
setError('Invalid state')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { useAuth } from '@/lib/auth/context'
|
||||
import { useOnlineStatus } from '@/lib/hooks/useOnlineStatus'
|
||||
import Link from 'next/link'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { logger } from '@/lib/utils/logger'
|
||||
import { getUserOrganizations, switchContext } from '@/lib/api/organization'
|
||||
import { setSessionAction } from '@/app/actions/auth'
|
||||
import { LoadingOverlay } from '@ciphera-net/ui'
|
||||
@@ -39,7 +40,7 @@ export default function LayoutContent({ children }: { children: React.ReactNode
|
||||
if (auth.user) {
|
||||
getUserOrganizations()
|
||||
.then((organizations) => setOrgs(Array.isArray(organizations) ? organizations : []))
|
||||
.catch(err => console.error('Failed to fetch orgs for header', err))
|
||||
.catch(err => logger.error('Failed to fetch orgs for header', err))
|
||||
}
|
||||
}, [auth.user])
|
||||
|
||||
@@ -51,7 +52,7 @@ export default function LayoutContent({ children }: { children: React.ReactNode
|
||||
sessionStorage.setItem(ORG_SWITCH_KEY, 'true')
|
||||
window.location.reload()
|
||||
} catch (err) {
|
||||
console.error('Failed to switch organization', err)
|
||||
logger.error('Failed to switch organization', err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useAuth } from '@/lib/auth/context'
|
||||
import { logger } from '@/lib/utils/logger'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { useParams, useRouter } from 'next/navigation'
|
||||
import { motion } from 'framer-motion'
|
||||
@@ -85,7 +86,7 @@ export default function SiteDashboardPage() {
|
||||
if (settings.multiDayInterval) setMultiDayInterval(settings.multiDayInterval)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load dashboard settings', e)
|
||||
logger.error('Failed to load dashboard settings', e)
|
||||
} finally {
|
||||
setIsSettingsLoaded(true)
|
||||
}
|
||||
@@ -103,7 +104,7 @@ export default function SiteDashboardPage() {
|
||||
}
|
||||
localStorage.setItem('pulse_dashboard_settings', JSON.stringify(settings))
|
||||
} catch (e) {
|
||||
console.error('Failed to save dashboard settings', e)
|
||||
logger.error('Failed to save dashboard settings', e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useEffect } from 'react'
|
||||
import { logger } from '@/lib/utils/logger'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import Link from 'next/link'
|
||||
import { createSite, listSites, getSite, type Site } from '@/lib/api/sites'
|
||||
@@ -65,7 +66,7 @@ export default function NewSitePage() {
|
||||
router.replace('/')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to check limits', error)
|
||||
logger.error('Failed to check limits', error)
|
||||
} finally {
|
||||
setLimitsChecked(true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user