fix(frontend): don't poll for updates when user not authorised

This commit is contained in:
tigattack
2025-09-22 22:13:36 +01:00
parent 001b234ecc
commit 69a121cdde

View File

@@ -1,6 +1,7 @@
import React, { createContext, useContext, useState } from 'react'
import { useQuery } from '@tanstack/react-query'
import { versionAPI } from '../utils/api'
import { versionAPI, settingsAPI } from '../utils/api'
import { useAuth } from './AuthContext'
const UpdateNotificationContext = createContext()
@@ -14,6 +15,15 @@ export const useUpdateNotification = () => {
export const UpdateNotificationProvider = ({ children }) => {
const [dismissed, setDismissed] = useState(false)
const { user, token } = useAuth()
// Ensure settings are loaded
const { data: settings, isLoading: settingsLoading } = useQuery({
queryKey: ['settings'],
queryFn: () => settingsAPI.get().then(res => res.data),
enabled: !!(user && token),
retry: 1
})
// Query for update information
const { data: updateData, isLoading, error } = useQuery({
@@ -21,7 +31,8 @@ export const UpdateNotificationProvider = ({ children }) => {
queryFn: () => versionAPI.checkUpdates().then(res => res.data),
staleTime: 10 * 60 * 1000, // Data stays fresh for 10 minutes
refetchOnWindowFocus: false, // Don't refetch when window regains focus
retry: 1
retry: 1,
enabled: !!(user && token && settings && !settingsLoading) // Only run when authenticated and settings are loaded
})
const updateAvailable = updateData?.isUpdateAvailable && !dismissed