@@ -42,12 +42,13 @@ import About from "./About"
4242import AppContextProvider from "./context/AppContext" ;
4343import TableReportConfigPage from "./domain/reports/TableReportConfigPage" ;
4444import TableReportPage from "./domain/reports/TableReportPage" ;
45- import { createUserManager , onSigninCallback } from "./auth/oidc" ;
45+ import { createUserManager } from "./auth/oidc" ;
4646import { AuthProvider } from "react-oidc-context" ;
4747import { KeycloakConfig } from "./generated" ;
4848import { configApi } from "./api" ;
4949import AuthBridgeContextProvider , { AuthBridgeContext } from "./context/AuthBridgeContext" ;
5050import { AuthContextType } from "./context/@types/authContextTypes" ;
51+ import { User } from "oidc-client-ts" ;
5152import CallbackSSO from "./auth/CallbackSSO" ;
5253
5354const router = createBrowserRouter (
@@ -92,20 +93,33 @@ const router = createBrowserRouter(
9293export default function App ( ) {
9394 const [ horreumOidcConfig , setHorreumOidcConfig ] = useState < KeycloakConfig | undefined > ( )
9495
96+ const onSignInCallback = ( user : User | undefined ) => {
97+ // TODO: find a way to get rid of the CallbackSSO route and use this callback to redirect to the last visited page
98+ const redirectUrl = ( user ?. state as { history ?: string } ) . history ;
99+ window . history . replaceState ( { } , document . title , redirectUrl ) ;
100+ } ;
101+
102+ const onSignOutCallback = ( ) => {
103+ window . history . replaceState ( { } , document . title , window . location . pathname ) ;
104+ } ;
105+
95106 useEffect ( ( ) => {
96107 configApi . keycloak ( ) . then ( setHorreumOidcConfig )
97108 } , [ ] ) ;
98109
99110 if ( ! horreumOidcConfig ) {
100- return < Bullseye >
101- < Spinner />
102- </ Bullseye >
111+ return (
112+ < Bullseye >
113+ < Spinner />
114+ </ Bullseye >
115+ )
103116 }
104117
105118 // if using oidc let's wrap the entire app with AuthProvider
106119 const userManager = createUserManager ( horreumOidcConfig )
120+
107121 return (
108- < AuthProvider userManager = { userManager } onSigninCallback = { onSigninCallback } >
122+ < AuthProvider userManager = { userManager } onSigninCallback = { onSignInCallback } onSignoutCallback = { onSignOutCallback } >
109123 { /* if url is empty or null -> use basic authentication */ }
110124 < AuthBridgeContextProvider isOidc = { horreumOidcConfig . url !== undefined && horreumOidcConfig . url !== "" } >
111125 < AppContextProvider >
0 commit comments