App.tsx
1 import React, { useEffect } from "react"; 2 import SwitchRoute from "./pages"; 3 import { Provider } from "react-redux"; 4 import store from "./redux/Store"; 5 import { useTranslation } from "react-i18next"; 6 //import "./App.scss"; 7 import { AuthClient } from "@dfinity/auth-client"; 8 import { handleLoginApp } from "@redux/CheckAuth"; 9 import { setAuth } from "@redux/auth/AuthReducer"; 10 11 const App: React.FC = () => { 12 const { i18n } = useTranslation(); 13 14 useEffect(() => { 15 const language = localStorage.getItem("language"); 16 if ( 17 language !== undefined && 18 language !== null && 19 language !== "" && 20 language !== "null" 21 ) { 22 i18n.changeLanguage(language); 23 } 24 }, [i18n]); 25 26 useEffect(() => { 27 const getIdentity = async () => { 28 const authClient = await AuthClient.create(); 29 const valid = await authClient.isAuthenticated(); 30 if (valid) { 31 handleLoginApp(authClient.getIdentity()); 32 } else { 33 store.dispatch(setAuth()); 34 } 35 }; 36 getIdentity().catch(console.error); 37 }, []); 38 39 return ( 40 <div className="App"> 41 <Provider store={store}> 42 <SwitchRoute></SwitchRoute> 43 </Provider> 44 </div> 45 ); 46 }; 47 48 export default App;