@@ -16,44 +16,7 @@ export default function Check() {
1616
1717 let history = useHistory ( )
1818
19- function authCheck ( ) {
20- // console.log('authCheck startfetch @ ' + DateTime.local().toFormat('HH:mm:ss.SSS'))
21- fetch ( 'http://localhost:5000/api/user/test_auth' ,
22- {
23- method : 'GET' ,
24- headers : {
25- 'Content-Type' : 'application/json' ,
26- 'Authorization' : 'Bearer ' + access_token
27- }
28- } )
29-
30- . then ( ( response ) => {
31- // console.log('authCheck handle response @ ' + DateTime.local().toFormat('HH:mm:ss.SSS'))
32- if ( ! response . ok ) {
33- //throw (String(response.status + ':' + response.statusText))
34- throw ( response )
35- }
36- return response . json ( )
37- } )
38- . then ( ( data ) => {
39- // console.log('authCheck data @ ' + DateTime.local().toFormat('HH:mm:ss.SSS'))
40- setProcessStatus ( 'complete' ) ;
41- setData ( data ) ;
42- } )
43- . catch ( ( e ) => {
44- let errCode = e . status
45- let errText = e . statusText
46-
47- setToken ( null ) // Clear the token to force login again
48- let errStr = String ( e )
49- setProcessStatus ( 'error' ) ;
50- setError ( errStr ) ;
51- console . log ( errCode + ':' + errText )
52- history . push ( '/' )
53- return e
54- } ) ;
55-
56- } //
19+
5720
5821
5922
@@ -68,6 +31,59 @@ export default function Check() {
6831
6932 React . useEffect ( ( ) => {
7033
34+
35+
36+ function authCheck ( ) {
37+ // console.log('authCheck startfetch @ ' + DateTime.local().toFormat('HH:mm:ss.SSS'))
38+ fetch ( 'http://localhost:5000/api/user/test_auth' ,
39+ {
40+ method : 'GET' ,
41+ headers : {
42+ 'Content-Type' : 'application/json' ,
43+ 'Authorization' : 'Bearer ' + access_token
44+ }
45+ } )
46+
47+ . then ( ( response ) => {
48+ // console.log('authCheck handle response @ ' + DateTime.local().toFormat('HH:mm:ss.SSS'))
49+ if ( ! response . ok ) {
50+ //throw (String(response.status + ':' + response.statusText))
51+ throw ( response )
52+ }
53+ return response . json ( )
54+ } )
55+ . then ( ( data ) => {
56+ // console.log('authCheck data @ ' + DateTime.local().toFormat('HH:mm:ss.SSS'))
57+ setProcessStatus ( 'complete' ) ;
58+ setData ( data ) ;
59+ } )
60+ . catch ( ( e ) => {
61+ let errCode = e . status
62+ let errText = e . statusText
63+
64+ setToken ( null ) // Clear the token to force login again
65+ let errStr = String ( e )
66+ setProcessStatus ( 'error' ) ;
67+ setError ( errStr ) ;
68+ console . log ( errCode + ':' + errText )
69+ history . push ( '/' )
70+ return e
71+ } ) ;
72+
73+ } //
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
7187 if ( ! access_token ) {
7288 console . log ( "In Check w/o a token" )
7389 }
@@ -77,7 +93,9 @@ export default function Check() {
7793 // console.log('After authCheck @ ' + DateTime.local().toFormat('HH:mm:ss.SSS'))
7894
7995
80- } , [ processStatus , access_token ] ) ;
96+ } ,
97+ // eslint-disable-next-line
98+ [ processStatus , access_token , history ] ) ;
8199
82100 // if (processStatus === 'loading') {
83101 // console.log('Check: if pc=l loading...')
0 commit comments