0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

Merge pull request #741 from logto-io/charles-fix-settings-api-401

fix(console): call settings API after user authentication
This commit is contained in:
Charles Zhao 2022-05-06 17:26:54 +08:00 committed by GitHub
commit 749c820cc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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;