@@ -7,24 +7,6 @@ export default function Home() {
77 const [ enabled , setEnabled ] = useState ( [ ] )
88 const [ passwordLogin , setPasswordLogin ] = useState ( [ ] )
99
10- async function whoami ( ) {
11- if ( typeof window === 'undefined' ) return
12- const { body } = await fetchApi ( '/api/whoami' )
13- if ( body . piboxConfigUser ) {
14- getSshSettings ( )
15- } else {
16- window . location . href = '/login'
17- }
18- }
19-
20- async function getSshSettings ( ) {
21- if ( typeof window === 'undefined' ) return
22- const { body } = await fetchApi ( '/api/ssh' )
23- setLoading ( false )
24- setEnabled ( body . enabled )
25- setPasswordLogin ( body . passwordLogin )
26- }
27-
2810 async function updateSshSettings ( { enabled, passwordLogin } ) {
2911 setLoading ( true )
3012 setEnabled ( enabled )
@@ -37,7 +19,26 @@ export default function Home() {
3719 setLoading ( false )
3820 }
3921
40- useEffect ( ( ) => whoami ( ) , [ ] )
22+ useEffect ( ( ) => {
23+ async function whoami ( ) {
24+ if ( typeof window === 'undefined' ) return
25+ const { body } = await fetchApi ( '/api/whoami' )
26+ if ( body . piboxConfigUser ) {
27+ getSshSettings ( )
28+ } else {
29+ window . location . href = '/login'
30+ }
31+ }
32+
33+ async function getSshSettings ( ) {
34+ if ( typeof window === 'undefined' ) return
35+ const { body } = await fetchApi ( '/api/ssh' )
36+ setLoading ( false )
37+ setEnabled ( body . enabled )
38+ setPasswordLogin ( body . passwordLogin )
39+ }
40+ whoami ( )
41+ } , [ ] )
4142
4243 return (
4344 < >
0 commit comments