0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00

fix(console): call settings API after user authentication

This commit is contained in:
Charles Zhao 2022-05-06 16:21:22 +08:00
parent a0355872c6
commit 3f25d4e6f6
No known key found for this signature in database
GPG key ID: 4858774754C92DF2

View file

@ -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<Setting>();
const { data } = useSWR<Setting, RequestError>('/api/settings', settingsFetcher);
const { data } = useSWR<Setting, RequestError>(
isAuthenticated && '/api/settings',
settingsFetcher
);
useEffect(() => {
const theme = data?.adminConsole.appearanceMode ?? defaultTheme;