@@ -60,77 +60,72 @@ const useLogout = (): Logout => {
6060 const logout : Logout = useCallback (
6161 (
6262 params = { } ,
63- redirectTo = loginUrl ,
63+ redirectFromCaller ,
6464 redirectToCurrentLocationAfterLogin = true
6565 ) => {
6666 if ( authProvider ) {
67- return authProvider
68- . logout ( params )
69- . then ( redirectToFromProvider => {
70- if (
71- redirectToFromProvider === false ||
72- redirectTo === false
73- ) {
74- resetStore ( ) ;
75- queryClient . clear ( ) ;
76- // do not redirect
77- return ;
78- }
67+ return authProvider . logout ( params ) . then ( redirectFromLogout => {
68+ if (
69+ redirectFromLogout === false ||
70+ redirectFromCaller === false
71+ ) {
72+ resetStore ( ) ;
73+ queryClient . clear ( ) ;
74+ // do not redirect
75+ return ;
76+ }
7977
80- const finalRedirectTo =
81- redirectToFromProvider || redirectTo ;
78+ const finalRedirectTo =
79+ redirectFromCaller || redirectFromLogout || loginUrl ;
8280
83- if ( finalRedirectTo ?. startsWith ( 'http' ) ) {
84- // absolute link (e.g. https://my.oidc.server/login)
85- resetStore ( ) ;
86- queryClient . clear ( ) ;
87- window . location . href = finalRedirectTo ;
88- return finalRedirectTo ;
89- }
81+ if ( finalRedirectTo ?. startsWith ( 'http' ) ) {
82+ // absolute link (e.g. https://my.oidc.server/login)
83+ resetStore ( ) ;
84+ queryClient . clear ( ) ;
85+ window . location . href = finalRedirectTo ;
86+ return finalRedirectTo ;
87+ }
9088
91- // redirectTo is an internal location that may contain a query string, e.g. '/login?foo=bar'
92- // we must split it to pass a structured location to navigate()
93- const redirectToParts = finalRedirectTo . split ( '?' ) ;
94- const newLocation : Partial < Path > = {
95- pathname : redirectToParts [ 0 ] ,
96- } ;
97- let newLocationOptions = { } ;
89+ // redirectTo is an internal location that may contain a query string, e.g. '/login?foo=bar'
90+ // we must split it to pass a structured location to navigate()
91+ const redirectToParts = finalRedirectTo . split ( '?' ) ;
92+ const newLocation : Partial < Path > = {
93+ pathname : redirectToParts [ 0 ] ,
94+ } ;
95+ let newLocationOptions = { } ;
9896
99- if (
100- redirectToCurrentLocationAfterLogin &&
101- locationRef . current &&
102- locationRef . current . pathname
103- ) {
104- newLocationOptions = {
105- state : {
106- nextPathname : locationRef . current . pathname ,
107- nextSearch : locationRef . current . search ,
108- } ,
109- } ;
110- }
111- if ( redirectToParts [ 1 ] ) {
112- newLocation . search = redirectToParts [ 1 ] ;
113- }
97+ if (
98+ redirectToCurrentLocationAfterLogin &&
99+ locationRef . current &&
100+ locationRef . current . pathname
101+ ) {
102+ newLocationOptions = {
103+ state : {
104+ nextPathname : locationRef . current . pathname ,
105+ nextSearch : locationRef . current . search ,
106+ } ,
107+ } ;
108+ }
109+ if ( redirectToParts [ 1 ] ) {
110+ newLocation . search = redirectToParts [ 1 ] ;
111+ }
114112
115- // We need to navigate and reset the store after a litte delay to avoid a race condition
116- // between the store reset and the navigation.
117- //
118- // This would only happen when the `authProvider.getPermissions` method returns
119- // a resolved promise with no delay: If the store was reset before the navigation,
120- // the `usePermissions` query would reset, causing the `CoreAdminRoutes` component to
121- // rerender the `LogoutOnMount` component leading to an infinite loop.
122- setTimeout ( ( ) => {
123- navigateRef . current (
124- newLocation ,
125- newLocationOptions
126- ) ;
113+ // We need to navigate and reset the store after a litte delay to avoid a race condition
114+ // between the store reset and the navigation.
115+ //
116+ // This would only happen when the `authProvider.getPermissions` method returns
117+ // a resolved promise with no delay: If the store was reset before the navigation,
118+ // the `usePermissions` query would reset, causing the `CoreAdminRoutes` component to
119+ // rerender the `LogoutOnMount` component leading to an infinite loop.
120+ setTimeout ( ( ) => {
121+ navigateRef . current ( newLocation , newLocationOptions ) ;
127122
128- resetStore ( ) ;
129- queryClient . clear ( ) ;
130- } , 0 ) ;
123+ resetStore ( ) ;
124+ queryClient . clear ( ) ;
125+ } , 0 ) ;
131126
132- return redirectToFromProvider ;
133- } ) ;
127+ return redirectFromLogout ;
128+ } ) ;
134129 } else {
135130 navigateRef . current (
136131 {
0 commit comments