import './App.css' import { useAuth, hasAuthParams } from "react-oidc-context"; import React, {useState} from 'react'; import { SettingOutlined, UserOutlined, } from '@ant-design/icons'; import {Breadcrumb, type MenuProps} from 'antd'; import { Layout, Menu, theme } from 'antd'; import Home from "./Home.tsx"; import { Route, Routes, useNavigate} from "react-router"; import Profile from "./Profile.tsx"; import {type UserContextType} from './UserContext.tsx'; import {UserContext} from './UserContext.tsx'; import type {userObject} from "./UserContext.tsx"; const { Header, Content, Sider } = Layout; type MenuItem = Required['items'][number]; function getItem( label: React.ReactNode, key: React.Key, icon?: React.ReactNode, children?: MenuItem[], ): MenuItem { return { key, icon, children, label, } as MenuItem; } const App: React.FC = () => { const navigate = useNavigate(); const { token: {colorBgContainer, borderRadiusLG}, } = theme.useToken(); /******************* SIGNING IN WITH OIDC *******************/ const auth = useAuth(); const hasTriedSignin = React.useRef(false); // automatically sign-in React.useEffect(() => { if (!hasAuthParams() && !auth.isAuthenticated && !auth.activeNavigator && !auth.isLoading && !hasTriedSignin.current ) { auth.signinRedirect(); hasTriedSignin.current = true; } }, [auth]); const defaultUser: UserContextType = { currentUser: { first_name: "", last_name: "", email: "", organisations: [] }, setCurrentUser: () => {} } const [currentUser, setCurrentUser] = useState(defaultUser.currentUser); /***************************** GETTING CURRENT USER FROM API *****************************/ // const [current_user, setUser] = useState(null); React.useEffect(() => { (async () => { if (!auth.user) { return } try { console.log(auth.user); const token = auth.user.access_token; const response = await fetch("/api/v1/user/self/db", { headers: { Authorization: `Bearer ${token}`, }, }); setCurrentUser(await response.json()); } catch (e) { console.error(e); } })(); }, [auth]); // const [current_orgs, set_current_orgs] = useState(null); if (!currentUser) { return(
Determining your existing user...
;
); } if (auth.isLoading) { return(
Signing you in/out...
;
); } if (!auth.isAuthenticated) { return(
Unable to log in
;
); } const onClick: MenuProps['onClick'] = (e) => { switch (e.key) { case 'account': navigate('/profile'); break; case 'logout': auth.removeUser().then(r => navigate('/profile')); break; default: console.log('Clicked item:', e.key); } }; //const organisations: [] = current_user.organisations; const side_nav_items: MenuItem[] = currentUser.organisations && [ getItem('Files', '9', ), ]; const top_nav_items = [ getItem(currentUser.first_name + " " +currentUser.last_name , 'account1', , [getItem('Account details', 'account'), getItem('Log out', 'logout')]), getItem("Organisation Settings", 'orgsettings', ), ]; return (

SR22

}/> {currentUser && }/> } ); } export default App