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:
parent
a0355872c6
commit
3f25d4e6f6
1 changed files with 6 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { LogtoProvider } from '@logto/react';
|
import { LogtoProvider, useLogto } from '@logto/react';
|
||||||
import { AppearanceMode, Setting } from '@logto/schemas';
|
import { AppearanceMode, Setting } from '@logto/schemas';
|
||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { BrowserRouter, Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom';
|
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 defaultTheme = localStorage.getItem(themeStorageKey) ?? AppearanceMode.SyncWithSystem;
|
||||||
|
|
||||||
const Main = () => {
|
const Main = () => {
|
||||||
|
const { isAuthenticated } = useLogto();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const fetcher = useSwrFetcher();
|
const fetcher = useSwrFetcher();
|
||||||
|
|
||||||
const settingsFetcher = useSwrFetcher<Setting>();
|
const settingsFetcher = useSwrFetcher<Setting>();
|
||||||
const { data } = useSWR<Setting, RequestError>('/api/settings', settingsFetcher);
|
const { data } = useSWR<Setting, RequestError>(
|
||||||
|
isAuthenticated && '/api/settings',
|
||||||
|
settingsFetcher
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const theme = data?.adminConsole.appearanceMode ?? defaultTheme;
|
const theme = data?.adminConsole.appearanceMode ?? defaultTheme;
|
||||||
|
|
Loading…
Add table
Reference in a new issue