Skip to content

Commit dca3811

Browse files
authored
Merge pull request #247 from CodeForPhilly/246-clean-ui-warnings
Cleanups and overrides to eliminate npm warnings
2 parents 070e944 + e8142d0 commit dca3811

File tree

2 files changed

+60
-43
lines changed

2 files changed

+60
-43
lines changed

src/client/src/App.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react'
22

33
import {BrowserRouter as Router, Switch, Route} from 'react-router-dom';
4-
54
import Header, {AdminHeader} from "./components/Header";
65

76
import HomePage from './pages/Home';
@@ -71,7 +70,7 @@ function AuthenticatedApp() {
7170

7271

7372
var decoded = jwt.decode(access_token, { complete: true });
74-
const userName = decoded?.payload.sub;
73+
7574
const userRole = decoded?.payload.role;
7675
var expTime = decoded?.payload.exp - Date.now()/1000;
7776

@@ -123,13 +122,13 @@ function AuthenticatedApp() {
123122

124123
function Home() {
125124
const {user} = useAuthState()
125+
/*eslint no-unused-vars: ["warn", { "varsIgnorePattern": "access_token" }]*/
126126
const { access_token, setToken } = useToken();
127127
return user ? <AuthenticatedApp /> : <Login setToken={setToken} />
128128
}
129129

130130
function App() {
131-
const { access_token, setToken } = useToken();
132-
131+
133132
return (
134133
<AuthProvider>
135134
<div>

src/client/src/pages/Check/Check.js

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)