@@ -2,50 +2,45 @@ import type { UserState } from './core/state';
22import type { DRootProps } from '@react-devui/ui' ;
33import type { DLang } from '@react-devui/ui/utils/types' ;
44
5+ import { isNull } from 'lodash' ;
56import { useEffect , useMemo , useState } from 'react' ;
6- import { useTranslation } from 'react-i18next' ;
7- import { useNavigate } from 'react-router-dom' ;
87
98import { useAsync , useMount , useStorage } from '@react-devui/hooks' ;
109import { DNotification , DToast } from '@react-devui/ui' ;
1110import { DRoot } from '@react-devui/ui' ;
1211
1312import { AppRoutes } from './Routes' ;
14- import { LOGIN_PATH } from './config/other' ;
1513import { STORAGE_KEY } from './config/storage' ;
16- import { useHttp , useInit } from './core' ;
14+ import { TOKEN , useHttp , useInit } from './core' ;
1715import { useNotifications , useToasts } from './core/state' ;
1816
1917export type AppTheme = 'light' | 'dark' ;
2018
2119export function App ( ) {
22- const { i18n } = useTranslation ( ) ;
2320 const http = useHttp ( ) ;
2421 const init = useInit ( ) ;
25- const navigate = useNavigate ( ) ;
2622 const async = useAsync ( ) ;
27- const [ loading , setLoading ] = useState ( true ) ;
23+ const [ loading , setLoading ] = useState ( ! isNull ( TOKEN . value ) ) ;
2824 const languageStorage = useStorage < DLang > ( ...STORAGE_KEY . language ) ;
2925 const themeStorage = useStorage < AppTheme > ( ...STORAGE_KEY . theme ) ;
3026 const [ notifications ] = useNotifications ( ) ;
3127 const [ toasts ] = useToasts ( ) ;
3228
3329 useMount ( ( ) => {
34- i18n . changeLanguage ( languageStorage . value ) ;
35-
36- http < UserState > ( {
37- url : '/auth/me' ,
38- method : 'get' ,
39- } ) . subscribe ( {
40- next : ( res ) => {
41- setLoading ( false ) ;
42- init ( res ) ;
43- } ,
44- error : ( ) => {
45- setLoading ( false ) ;
46- navigate ( LOGIN_PATH ) ;
47- } ,
48- } ) ;
30+ if ( ! isNull ( TOKEN . value ) ) {
31+ http < UserState > ( {
32+ url : '/auth/me' ,
33+ method : 'get' ,
34+ } ) . subscribe ( {
35+ next : ( res ) => {
36+ setLoading ( false ) ;
37+ init ( res ) ;
38+ } ,
39+ error : ( ) => {
40+ setLoading ( false ) ;
41+ } ,
42+ } ) ;
43+ }
4944 } ) ;
5045
5146 useEffect ( ( ) => {
0 commit comments