diff --git a/packages/console/src/App.tsx b/packages/console/src/App.tsx index 087aa16ea..2d5913d3a 100644 --- a/packages/console/src/App.tsx +++ b/packages/console/src/App.tsx @@ -1,4 +1,4 @@ -import { LogtoProvider } from '@logto/react'; +import { LogtoProvider, useLogto } from '@logto/react'; import { AppearanceMode, Setting } from '@logto/schemas'; import React, { useEffect } from 'react'; import { BrowserRouter, Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom'; @@ -33,12 +33,16 @@ void initI18n(); const defaultTheme = localStorage.getItem(themeStorageKey) ?? AppearanceMode.SyncWithSystem; const Main = () => { + const { isAuthenticated } = useLogto(); const location = useLocation(); const navigate = useNavigate(); const fetcher = useSwrFetcher(); const settingsFetcher = useSwrFetcher(); - const { data } = useSWR('/api/settings', settingsFetcher); + const { data } = useSWR( + isAuthenticated && '/api/settings', + settingsFetcher + ); useEffect(() => { const theme = data?.adminConsole.appearanceMode ?? defaultTheme;