Skip to content

Commit 484feb8

Browse files
committed
Merge branch 'auth-button' into staging-watchonly
2 parents bf1a4ee + 6b595ab commit 484feb8

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

frontends/web/src/components/auth/authrequired.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@ import { View } from '../view/view';
1818
import style from './authrequired.module.css';
1919
import { useEffect, useRef, useState } from 'react';
2020
import { TAuthEventObject, authenticate, subscribeAuth } from '../../api/backend';
21+
import { Button } from '../forms';
22+
import { useTranslation } from 'react-i18next';
2123

2224
export const AuthRequired = () => {
25+
const { t } = useTranslation();
2326
const [authRequired, setAuthRequired] = useState(false);
27+
const [authenticating, setAuthenticating] = useState(false);
2428
const authForced = useRef(false);
2529

30+
const newAuthentication = () => {
31+
setAuthenticating(true);
32+
authenticate(authForced.current);
33+
};
34+
2635
useEffect(() => {
2736
const unsubscribe = subscribeAuth((data: TAuthEventObject) => {
2837
switch (data.typ) {
@@ -36,13 +45,13 @@ export const AuthRequired = () => {
3645
// time the state changes.
3746
setAuthRequired((prevAuthRequired) => {
3847
if (!prevAuthRequired) {
39-
authenticate(authForced.current);
48+
newAuthentication();
4049
}
4150
return true;
4251
});
4352
break;
4453
case 'auth-err':
45-
authenticate(authForced.current);
54+
setAuthenticating(false);
4655
break;
4756
case 'auth-canceled':
4857
if (authForced.current) {
@@ -52,7 +61,7 @@ export const AuthRequired = () => {
5261
setAuthRequired(false);
5362
authForced.current = false;
5463
} else {
55-
authenticate(authForced.current);
64+
setAuthenticating(false);
5665
}
5766
break;
5867
case 'auth-ok':
@@ -64,7 +73,7 @@ export const AuthRequired = () => {
6473
// Perform initial authentication. If the auth config is disabled,
6574
// the backend will immediately send an auth-ok back.
6675
setAuthRequired(true);
67-
authenticate();
76+
newAuthentication();
6877

6978
return unsubscribe;
7079
}, []);
@@ -80,6 +89,15 @@ export const AuthRequired = () => {
8089
verticallyCentered
8190
width="100%"
8291
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>
83101
</View>
84102
</div>
85103
);

frontends/web/src/locales/en/app.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@
8484
"app": {
8585
"upgrade": "A new version of this app is available! Please upgrade from {{current}} to {{version}}."
8686
},
87+
"auth": {
88+
"authButton": "Authenticate",
89+
"title": "Please authenticate to continue"
90+
},
8791
"backup": {
8892
"check": {
8993
"checking": "Checking backup…",

0 commit comments

Comments
 (0)