@@ -18,11 +18,20 @@ import { View } from '../view/view';
18
18
import style from './authrequired.module.css' ;
19
19
import { useEffect , useRef , useState } from 'react' ;
20
20
import { TAuthEventObject , authenticate , subscribeAuth } from '../../api/backend' ;
21
+ import { Button } from '../forms' ;
22
+ import { useTranslation } from 'react-i18next' ;
21
23
22
24
export const AuthRequired = ( ) => {
25
+ const { t } = useTranslation ( ) ;
23
26
const [ authRequired , setAuthRequired ] = useState ( false ) ;
27
+ const [ authenticating , setAuthenticating ] = useState ( false ) ;
24
28
const authForced = useRef ( false ) ;
25
29
30
+ const newAuthentication = ( ) => {
31
+ setAuthenticating ( true ) ;
32
+ authenticate ( authForced . current ) ;
33
+ } ;
34
+
26
35
useEffect ( ( ) => {
27
36
const unsubscribe = subscribeAuth ( ( data : TAuthEventObject ) => {
28
37
switch ( data . typ ) {
@@ -36,13 +45,13 @@ export const AuthRequired = () => {
36
45
// time the state changes.
37
46
setAuthRequired ( ( prevAuthRequired ) => {
38
47
if ( ! prevAuthRequired ) {
39
- authenticate ( authForced . current ) ;
48
+ newAuthentication ( ) ;
40
49
}
41
50
return true ;
42
51
} ) ;
43
52
break ;
44
53
case 'auth-err' :
45
- authenticate ( authForced . current ) ;
54
+ setAuthenticating ( false ) ;
46
55
break ;
47
56
case 'auth-canceled' :
48
57
if ( authForced . current ) {
@@ -52,7 +61,7 @@ export const AuthRequired = () => {
52
61
setAuthRequired ( false ) ;
53
62
authForced . current = false ;
54
63
} else {
55
- authenticate ( authForced . current ) ;
64
+ setAuthenticating ( false ) ;
56
65
}
57
66
break ;
58
67
case 'auth-ok' :
@@ -64,7 +73,7 @@ export const AuthRequired = () => {
64
73
// Perform initial authentication. If the auth config is disabled,
65
74
// the backend will immediately send an auth-ok back.
66
75
setAuthRequired ( true ) ;
67
- authenticate ( ) ;
76
+ newAuthentication ( ) ;
68
77
69
78
return unsubscribe ;
70
79
} , [ ] ) ;
@@ -80,6 +89,15 @@ export const AuthRequired = () => {
80
89
verticallyCentered
81
90
width = "100%"
82
91
withBottomBar >
92
+ < h2 > < span > { t ( 'auth.title' ) } </ span > </ h2 >
93
+ < Button
94
+ autoFocus
95
+ primary
96
+ hidden = { authForced . current }
97
+ disabled = { authenticating }
98
+ onClick = { newAuthentication } >
99
+ { t ( 'auth.authButton' ) }
100
+ </ Button >
83
101
</ View >
84
102
</ div >
85
103
) ;
0 commit comments