@@ -16,21 +16,29 @@ import { AuthForm } from "modules/components/AuthComponent/common-components";
1616import AuthLayout from "modules/containers/AuthLayout" ;
1717import ComingSoonPage from "modules/components/EmptyPageComponent/ComingSoon" ;
1818import Cookies from "js-cookie" ;
19- import LoginForm from "modules/components/AuthComponent/LoginForm" ;
2019import MainLayout from "modules/containers/MainLayout" ;
2120import NoMatchingPage from "modules/components/EmptyPageComponent/NoMatchingPage" ;
2221import OverviewComponent from "modules/components/OverviewComponent" ;
2322import ProfileComponent from "modules/components/ProfileComponent" ;
24- import SignupForm from "modules/components/AuthComponent/SignupForm" ;
2523import TableOfContent from "modules/components/TableOfContent" ;
2624import TableWithFavorite from "modules/components/TableComponent" ;
2725import favicon from "./assets/logo/favicon.ico" ;
2826import { fetchEndpoints } from "./actions/endpointAction" ;
29- import { getUserDetails } from "actions/authActions" ;
3027import { showToast } from "actions/toastActions" ;
31- import { useDispatch } from "react-redux" ;
28+ import { useDispatch , useSelector } from "react-redux" ;
29+ import { ReactKeycloakProvider } from '@react-keycloak/web' ;
3230
33- const ProtectedRoute = ( { redirectPath = APP_ROUTES . AUTH_LOGIN , children } ) => {
31+ const eventLogger = ( event , error ) => {
32+ // We might want to consider to refresh the tokens here
33+ // if the event === 'onTokenExpired'
34+ } ;
35+
36+ const tokenLogger = ( tokens ) => {
37+ // Placeholder for to perform action when new token is generated
38+ // console.log('onKeycloakTokens', tokens["refreshToken"]);
39+ } ;
40+
41+ const ProtectedRoute = ( { redirectPath = APP_ROUTES . AUTH , children } ) => {
3442 const loggedIn = Cookies . get ( "isLoggedIn" ) ;
3543 const dispatch = useDispatch ( ) ;
3644
@@ -47,25 +55,36 @@ const HomeRoute = ({ redirectPath = APP_ROUTES.HOME }) => {
4755
4856const App = ( ) => {
4957 const dispatch = useDispatch ( ) ;
58+ const { keycloak } = useSelector (
59+ state => state . apiEndpoint
60+ ) ;
5061
5162 useEffect ( ( ) => {
5263 const faviconLogo = document . getElementById ( "favicon" ) ;
5364 faviconLogo ?. setAttribute ( "href" , favicon ) ;
5465
5566 dispatch ( fetchEndpoints ) ;
56- dispatch ( getUserDetails ( ) ) ;
5767 } , [ dispatch ] ) ;
5868
5969 return (
6070 < div className = "App" >
71+ { keycloak && (
72+ < ReactKeycloakProvider
73+ authClient = { keycloak }
74+ onEvent = { eventLogger }
75+ onTokens = { tokenLogger }
76+ initOptions = { {
77+ onLoad :'check-sso' ,
78+ checkLoginIframe : true ,
79+ enableLogging : true
80+ } }
81+ >
6182 < BrowserRouter >
6283 < Routes >
6384 < Route path = "/" element = { < HomeRoute /> } > </ Route >
6485 < Route path = { "/" + APP_ROUTES . HOME } >
6586 < Route element = { < AuthLayout /> } >
66- < Route path = { APP_ROUTES . AUTH_LOGIN } element = { < LoginForm /> } />
6787 < Route path = { APP_ROUTES . AUTH } element = { < AuthForm /> } />
68- < Route path = { APP_ROUTES . AUTH_SIGNUP } element = { < SignupForm /> } />
6988 </ Route >
7089 < Route element = { < MainLayout /> } >
7190 < Route index element = { < TableWithFavorite /> } />
@@ -97,6 +116,8 @@ const App = () => {
97116 </ Route >
98117 </ Routes >
99118 </ BrowserRouter >
119+ </ ReactKeycloakProvider >
120+ ) }
100121 </ div >
101122 ) ;
102123} ;
0 commit comments