5
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
- import { Dispatch , useCallback } from 'react' ;
9
- import { Location , Navigate , NavigateFunction , Route , Routes } from 'react-router-dom' ;
10
- import { Alert , AlertTitle , Grid } from '@mui/material' ;
11
- import { FormattedMessage } from 'react-intl' ;
12
- import { UserManager } from 'oidc-client' ;
8
+ import { useCallback } from 'react' ;
9
+ import { Navigate , Route , Routes } from 'react-router-dom' ;
10
+ import { Grid } from '@mui/material' ;
11
+ import { AuthenticationRouterProps } from './authenticationType' ;
12
+ import AuthenticationRouterErrorDisplay from './AuthenticationRouterErrorDisplay' ;
13
+ import { handleSigninCallback , handleSilentRenewCallback , login } from './utils/authService' ;
13
14
import SignInCallbackHandler from './SignInCallbackHandler' ;
14
- import { handleSigninCallback , handleSilentRenewCallback , login , logout } from './utils/authService' ;
15
15
import SilentRenewCallbackHandler from './SilentRenewCallbackHandler' ;
16
16
import Login from './Login' ;
17
- import Logout from './Logout' ;
18
-
19
- import { AuthenticationActions } from '../../redux/actions/authActions' ;
20
-
21
- export type AuthenticationRouterErrorState = {
22
- userName ?: string ;
23
- userValidationError ?: { error : Error } ;
24
- logoutError ?: { error : Error } ;
25
- unauthorizedUserInfo ?: string ;
26
- } ;
27
-
28
- export type UserManagerState = {
29
- instance : UserManager | null ;
30
- error : string | null ;
31
- } ;
32
-
33
- export interface AuthenticationRouterProps {
34
- userManager : UserManagerState ;
35
- signInCallbackError : Error | null ;
36
- authenticationRouterError : AuthenticationRouterErrorState | null ;
37
- showAuthenticationRouterLogin : boolean ;
38
- dispatch : Dispatch < AuthenticationActions > ;
39
- navigate : NavigateFunction ;
40
- location : Location ;
41
- }
42
17
43
18
function AuthenticationRouter ( {
44
19
userManager,
@@ -50,12 +25,12 @@ function AuthenticationRouter({
50
25
location,
51
26
} : Readonly < AuthenticationRouterProps > ) {
52
27
const handleSigninCallbackClosure = useCallback ( ( ) => {
53
- if ( userManager . instance != null ) {
28
+ if ( userManager . instance ) {
54
29
handleSigninCallback ( dispatch , navigate , userManager . instance ) ;
55
30
}
56
31
} , [ dispatch , navigate , userManager . instance ] ) ;
57
32
const handleSilentRenewCallbackClosure = useCallback ( ( ) => {
58
- if ( userManager . instance != null ) {
33
+ if ( userManager . instance ) {
59
34
handleSilentRenewCallback ( userManager . instance ) ;
60
35
}
61
36
} , [ userManager . instance ] ) ;
@@ -103,57 +78,11 @@ function AuthenticationRouter({
103
78
</ Routes >
104
79
105
80
{ authenticationRouterError !== null && (
106
- < >
107
- < Grid item >
108
- < Logout
109
- disabled = { userManager . instance === null }
110
- onLogoutClick = { ( ) => logout ( dispatch , userManager . instance ) }
111
- />
112
- </ Grid >
113
- < Grid item xs = { 4 } >
114
- { authenticationRouterError . logoutError != null && (
115
- < Alert severity = "error" >
116
- < AlertTitle >
117
- < FormattedMessage id = "login/errorInLogout" />
118
- </ AlertTitle >
119
- < FormattedMessage
120
- id = "login/errorInLogoutMessage"
121
- values = { {
122
- userName : authenticationRouterError . userName ,
123
- } }
124
- />
125
- < p > { authenticationRouterError . logoutError . error . message } </ p >
126
- </ Alert >
127
- ) }
128
- { authenticationRouterError ?. userValidationError != null && (
129
- < Alert severity = "error" >
130
- < AlertTitle >
131
- < FormattedMessage id = "login/errorInUserValidation" />
132
- </ AlertTitle >
133
- < FormattedMessage
134
- id = "login/errorInUserValidationMessage"
135
- values = { {
136
- userName : authenticationRouterError . userName ,
137
- } }
138
- />
139
- < p > { authenticationRouterError . userValidationError . error . message } </ p >
140
- </ Alert >
141
- ) }
142
- { authenticationRouterError ?. unauthorizedUserInfo != null && (
143
- < Alert severity = "info" >
144
- < AlertTitle >
145
- < FormattedMessage id = "login/unauthorizedAccess" />
146
- </ AlertTitle >
147
- < FormattedMessage
148
- id = "login/unauthorizedAccessMessage"
149
- values = { {
150
- userName : authenticationRouterError . userName ,
151
- } }
152
- />
153
- </ Alert >
154
- ) }
155
- </ Grid >
156
- </ >
81
+ < AuthenticationRouterErrorDisplay
82
+ dispatch = { dispatch }
83
+ instance = { userManager . instance }
84
+ errorState = { authenticationRouterError }
85
+ />
157
86
) }
158
87
</ Grid >
159
88
) ;
0 commit comments