diff --git a/src/App.jsx b/src/App.jsx
index 32f888b..3fb77d6 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -2,13 +2,13 @@ import NavBar from '@/views/components/NavBar'
import { Button, Typography, useColorScheme } from '@mui/joy'
import Tracker from '@openreplay/tracker'
import { useCallback, useEffect } from 'react'
-import { Outlet, useNavigate } from 'react-router-dom'
+import { Outlet } from 'react-router-dom'
import { useRegisterSW } from 'virtual:pwa-register/react'
import { registerCapacitorListeners } from './CapacitorListener'
import PageTransition from './components/animations/PageTransition'
-import { AuthProvider } from './hooks/useAuth.jsx'
import { ImpersonateUserProvider } from './contexts/ImpersonateUserContext'
import SSEProvider from './contexts/SSEContext'
+import { AuthProvider } from './hooks/useAuth.jsx'
import { useNotification } from './service/NotificationProvider'
import NetworkBanner from './views/components/NetworkBanner'
@@ -32,7 +32,6 @@ const startOpenReplay = () => {
tracker.start()
}
-
const AppContent = () => {
const { showNotification } = useNotification()
diff --git a/src/hooks/useSSE.js b/src/hooks/useSSE.js
index 804d759..8a63f20 100644
--- a/src/hooks/useSSE.js
+++ b/src/hooks/useSSE.js
@@ -18,9 +18,9 @@ const MAX_RECONNECT_ATTEMPTS = 10 // Circuit breaker limit
const CIRCUIT_BREAKER_RESET_TIME = 600000 // 10 minutes
export const useSSE = () => {
- const { data: userProfile } = useUserProfile()
-
const { isAuthenticated, token } = useAuth()
+ // Only fetch user profile if authenticated - prevents unnecessary API calls on landing page
+ const { data: userProfile } = useUserProfile()
const [connectionState, setConnectionState] = useState(SSE_STATES.CLOSED)
const [lastEvent, setLastEvent] = useState(null)
const [error, setError] = useState(null)
diff --git a/src/queries/ResourceQueries.jsx b/src/queries/ResourceQueries.jsx
index 21a3679..8f79f31 100644
--- a/src/queries/ResourceQueries.jsx
+++ b/src/queries/ResourceQueries.jsx
@@ -1,6 +1,17 @@
import { useQuery } from '@tanstack/react-query'
import { GetResource } from '../utils/Fetcher'
+// Helper to check if we have a valid token
+const isTokenValid = () => {
+ const token = localStorage.getItem('token')
+ if (!token) return false
+
+ const expiry = localStorage.getItem('token_expiry')
+ if (!expiry) return true // No expiry set, assume valid
+
+ return new Date() < new Date(expiry)
+}
+
export const useResource = () => {
const { data, isLoading, error } = useQuery({
queryKey: ['resource'],
@@ -11,6 +22,7 @@ export const useResource = () => {
staleTime: 6 * 60 * 60 * 1000, // 6 hours in milliseconds
refetchOnWindowFocus: false,
refetchOnReconnect: false,
+ enabled: isTokenValid(), // Only run query when we have a valid token
})
return { data, isLoading, error }
}
diff --git a/src/queries/UserQueries.jsx b/src/queries/UserQueries.jsx
index 9ffe727..160de07 100644
--- a/src/queries/UserQueries.jsx
+++ b/src/queries/UserQueries.jsx
@@ -54,6 +54,7 @@ export const useUserProfile = () => {
},
staleTime: 30 * 60 * 1000, // 30 minutes in milliseconds
gcTime: 30 * 60 * 1000, // 30 minutes in milliseconds
+ enabled: isTokenValid(), // Only run query when we have a valid token
})
return {
data,
diff --git a/src/views/components/NavBar.jsx b/src/views/components/NavBar.jsx
index 24fe053..c83e1d1 100644
--- a/src/views/components/NavBar.jsx
+++ b/src/views/components/NavBar.jsx
@@ -115,7 +115,7 @@ const publicPages = [
'/',
]
-const AppNavBar = () => {
+const NavBar = () => {
const { data: resource } = useResource()
const navigate = useNavigate()
@@ -323,20 +323,4 @@ const AppNavBar = () => {
)
}
-
-const LandingNavBar = () => {
- return null
-}
-
-const NavBar = () => {
- // if capacitor app then show AppNavBar, else show LandingNavBar
- if (Capacitor.isNativePlatform()) {
- return
- }
- if (publicPages.includes(window.location.pathname)) {
- return
- }
- return
-}
-
export default NavBar