File tree Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ function AuthenticatedApp() {
82
82
console . log ( "expTime:" + String ( expTime ) . fixed ( 1 ) )
83
83
const jwtExpired = expTime <= 0
84
84
85
- const popRefreshAlert = expTime < 30 ;
85
+ const popRefreshAlert = expTime > 0 && expTime < 30 ;
86
86
if ( popRefreshAlert ) console . log ( "Time to refresh !!!!!!!!!!! " ) ;
87
87
88
88
const hdr = userRole === 'admin' ? < AdminHeader /> : < Header /> // If we're going to display a header, which one?
@@ -93,7 +93,9 @@ function AuthenticatedApp() {
93
93
94
94
{ ! jwtExpired && hdr ? hdr : '' /* Above-chosen header, or if logged out, no header */ }
95
95
96
- { popRefreshAlert && < CDialog setToken = { setToken } /> }
96
+ { popRefreshAlert && < CDialog shouldOpen = { true } setToken = { setToken } /> } { /* Pop up the refresh dialog */ }
97
+
98
+ { jwtExpired && < CDialog shouldOpen = { false } setToken = { setToken } /> } { /* Too late, expired: close the dialog */ }
97
99
98
100
99
101
{ /* If not logged in, show login screen */
Original file line number Diff line number Diff line change @@ -10,21 +10,23 @@ import useToken from '../components/Login/useToken';
10
10
11
11
import Refresh from './Refresh' ;
12
12
13
- export default function CDialog ( { setToken } ) {
14
- const [ open , setOpen ] = React . useState ( true ) ;
15
- const { access_token, setT } = useToken ( ) ;
13
+ export default function CDialog ( props ) {
14
+ const [ open , setOpen ] = React . useState ( props . shouldOpen ) ;
15
+ const { access_token, setT } = useToken ( ) ; // We want to use the passed-in top-level setToken
16
16
17
17
18
18
const handleClickOpen = ( ) => {
19
19
setOpen ( true ) ;
20
20
} ;
21
21
22
+
22
23
const handleClose = async ( shouldRefresh ) => {
24
+ // Could be closed with Yes, No, outclick (which equals No)
23
25
setOpen ( false ) ;
24
- console . log ( "Refresh? " + String ( shouldRefresh ) ) ;
25
- if ( shouldRefresh ) {
26
+ console . log ( "Refresh? " + String ( props . shouldOpen ) ) ;
27
+ if ( props . shouldOpen ) {
26
28
const new_at = await Refresh ( access_token ) ;
27
- setToken ( new_at ) ;
29
+ props . setToken ( new_at ) ;
28
30
}
29
31
} ;
30
32
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ var jwt = require('jsonwebtoken');
8
8
9
9
export default function Check ( { access_token} ) {
10
10
11
- const { local_a_t , setToken } = useToken ( ) ;
11
+ const { setToken } = useToken ( ) ;
12
12
13
13
const [ processStatus , setProcessStatus ] = React . useState ( 'loading' ) ;
14
14
const [ error , setError ] = React . useState ( '' ) ;
You can’t perform that action at this time.
0 commit comments