@@ -24,7 +24,7 @@ function Authentication({closable = false}: AuthenticationProps) {
2424 const history = useHistory ( ) ;
2525 const location = useLocation ( ) ;
2626
27- const [ authenticate , { error , isLoading} ] = authenticationApi . useAuthenticateMutation ( undefined ) ;
27+ const [ authenticate , { isLoading} ] = authenticationApi . useAuthenticateMutation ( undefined ) ;
2828
2929 const { returnUrl} = parseQuery ( location ) ;
3030
@@ -34,15 +34,6 @@ function Authentication({closable = false}: AuthenticationProps) {
3434 const [ passwordError , setPasswordError ] = React . useState ( '' ) ;
3535 const [ showPassword , setShowPassword ] = React . useState ( false ) ;
3636
37- React . useEffect ( ( ) => {
38- if ( isUserError ( error ) ) {
39- setLoginError ( error . data . error ) ;
40- }
41- if ( isPasswordError ( error ) ) {
42- setPasswordError ( error . data . error ) ;
43- }
44- } , [ error ] ) ;
45-
4637 const onLoginUpdate = ( value : string ) => {
4738 setLogin ( value ) ;
4839 setLoginError ( '' ) ;
@@ -54,18 +45,28 @@ function Authentication({closable = false}: AuthenticationProps) {
5445 } ;
5546
5647 const onLoginClick = ( ) => {
57- authenticate ( { user : login , password} ) . then ( ( ) => {
58- if ( returnUrl ) {
59- const decodedUrl = decodeURIComponent ( returnUrl . toString ( ) ) ;
60-
61- // to prevent page reload we use router history
62- // history navigates relative to origin
63- // so we remove origin to make it work properly
64- const url = new URL ( decodedUrl ) ;
65- const path = url . pathname + url . search ;
66- history . replace ( path ) ;
67- }
68- } ) ;
48+ authenticate ( { user : login , password} )
49+ . unwrap ( )
50+ . then ( ( ) => {
51+ if ( returnUrl ) {
52+ const decodedUrl = decodeURIComponent ( returnUrl . toString ( ) ) ;
53+
54+ // to prevent page reload we use router history
55+ // history navigates relative to origin
56+ // so we remove origin to make it work properly
57+ const url = new URL ( decodedUrl ) ;
58+ const path = url . pathname + url . search ;
59+ history . replace ( path ) ;
60+ }
61+ } )
62+ . catch ( ( error ) => {
63+ if ( isUserError ( error ) ) {
64+ setLoginError ( error . data . error ) ;
65+ }
66+ if ( isPasswordError ( error ) ) {
67+ setPasswordError ( error . data . error ) ;
68+ }
69+ } ) ;
6970 } ;
7071
7172 const onEnterClick = ( e : React . KeyboardEvent < HTMLInputElement | HTMLTextAreaElement > ) => {
0 commit comments