@@ -28,12 +28,27 @@ function Authentication({closable = false}: AuthenticationProps) {
2828
2929 const needDatabase = useLoginWithDatabase ( ) ;
3030
31- const useMeta = useMetaAuth ( ) ;
32-
3331 const [ authenticate , { isLoading} ] = authenticationApi . useAuthenticateMutation ( ) ;
3432
3533 const { returnUrl, database : databaseFromQuery } = parseQuery ( location ) ;
3634
35+ const path = React . useMemo ( ( ) => {
36+ let path : string | undefined ;
37+
38+ if ( returnUrl ) {
39+ const decodedUrl = decodeURIComponent ( returnUrl . toString ( ) ) ;
40+
41+ // to prevent page reload we use router history
42+ // history navigates relative to origin
43+ // so we remove origin to make it work properly
44+ const url = new URL ( decodedUrl ) ;
45+ path = url . pathname + url . search ;
46+ }
47+ return path ;
48+ } , [ returnUrl ] ) ;
49+
50+ const useMeta = useMetaAuth ( path ) ;
51+
3752 const [ login , setLogin ] = React . useState ( '' ) ;
3853 const [ database , setDatabase ] = React . useState ( databaseFromQuery ?. toString ( ) ?? '' ) ;
3954 const [ password , setPass ] = React . useState ( '' ) ;
@@ -60,14 +75,7 @@ function Authentication({closable = false}: AuthenticationProps) {
6075 authenticate ( { user : login , password, database, useMeta} )
6176 . unwrap ( )
6277 . then ( ( ) => {
63- if ( returnUrl ) {
64- const decodedUrl = decodeURIComponent ( returnUrl . toString ( ) ) ;
65-
66- // to prevent page reload we use router history
67- // history navigates relative to origin
68- // so we remove origin to make it work properly
69- const url = new URL ( decodedUrl ) ;
70- const path = url . pathname + url . search ;
78+ if ( path ) {
7179 history . replace ( path ) ;
7280 }
7381 } )
0 commit comments