diff --git a/src/components/flags/FlagsApi.js b/src/components/flags/FlagsApi.js index ef76102..51384b7 100644 --- a/src/components/flags/FlagsApi.js +++ b/src/components/flags/FlagsApi.js @@ -30,25 +30,33 @@ class FlagsApi extends React.Component { async handleClick(action) { if (action === 'api') { - const res = await axios.get(api.url+'/api/flags/test'); - this.props.dispatch( - {type : 'set', payload: - { 'text' : res.data.message, - 'flags' : res.data.flags, - 'ques' : res.data.ques, - 'answer' : res.data.answer, - 'answerCode' : res.data.answerCode, - 'counter' : this.props.counter, - 'lifes' : this.props.lifes, - 'lifesIcon' : this.props.lifesIcon, - 'timer' : this.props.timer, - 'interval' : this.props.interval, - 'maxTimer' : this.props.maxTimer, - 'sessionTimer' : this.props.sessionTimer, - 'flagi' : res.data.flags, + try { + const res = await axios.get(api.url+'/api/flags/test'); + this.props.dispatch( + {type : 'set', payload: + { 'text' : res.data.message, + 'flags' : res.data.flags, + 'ques' : res.data.ques, + 'answer' : res.data.answer, + 'answerCode' : res.data.answerCode, + 'counter' : this.props.counter, + 'lifes' : this.props.lifes, + 'lifesIcon' : this.props.lifesIcon, + 'timer' : this.props.timer, + 'interval' : this.props.interval, + 'maxTimer' : this.props.maxTimer, + 'sessionTimer' : this.props.sessionTimer, + 'flagi' : res.data.flags, + } } + ); + } catch (err) { + if (err.response && err.response.status === 401) { + this.handleUnauthorized(); + return; } - ); + throw err; + } } if (action === 'increment') { @@ -56,10 +64,26 @@ class FlagsApi extends React.Component { } if (action === 'protected') { - const res = await axios.get(api.url+'/api/flags/protected'); + try { + const res = await axios.get(api.url+'/api/flags/protected'); + } catch (err) { + if (err.response && err.response.status === 401) { + this.handleUnauthorized(); + return; + } + throw err; + } } } + handleUnauthorized = () => { + localStorage.removeItem('accessToken'); + localStorage.removeItem('refreshToken'); + localStorage.removeItem('tokenExpiresAt'); + this.props.dispatch({type : 'reset'}); + this.props.history.push('/'); + } + async answer(action) { if (this.props.lifes == 0) { return; } if (this.answerLocked) { return; } @@ -74,12 +98,19 @@ class FlagsApi extends React.Component { if (action === this.props.answer) { this.stopTimer(); - await axios.post(api.url+'/api/flags/correct/'+this.props.answerCode); + try { + await axios.post(api.url+'/api/flags/correct/'+this.props.answerCode); + } catch (err) { + if (err.response && err.response.status === 401) { + this.handleUnauthorized(); + return; + } + } this.props.dispatch({type : 'correct' }) setTimeout(() => { this.showFlags(); }, 1500); - + } else { this.showCorrect(); if (this.props.lifes == 1) { @@ -225,10 +256,15 @@ class FlagsApi extends React.Component { } } - submitScore(score, sessionTimer) { - const res = axios.post(api.url+'/api/flags/scores', { 'score' : score, 'sessionTimer' : sessionTimer, 'answers' : this.answers }); + async submitScore(score, sessionTimer) { + try { + await axios.post(api.url+'/api/flags/scores', { 'score' : score, 'sessionTimer' : sessionTimer, 'answers' : this.answers }); this.answers = []; - console.log(res); + } catch (err) { + if (err.response && err.response.status === 401) { + this.handleUnauthorized(); + } + } } componentDidMount() { diff --git a/src/components/home/Home.js b/src/components/home/Home.js index 8e47039..f004434 100644 --- a/src/components/home/Home.js +++ b/src/components/home/Home.js @@ -326,13 +326,17 @@ const Home = () => { Flags Quiz | {process.env.REACT_APP_VERSION || 'dev'} - -
- Feedback: admin@izeebot.top -
-
+ | + admin@izeebot.top + | © {new Date().getFullYear()}
+ {/*
*/} + {/* Feedback: admin@izeebot.top*/} + {/*
*/} + {/*
*/} + {/* */} + {/*
*/} diff --git a/src/hooks/useOAuth.js b/src/hooks/useOAuth.js index 8c9ac3e..303c295 100644 --- a/src/hooks/useOAuth.js +++ b/src/hooks/useOAuth.js @@ -41,7 +41,7 @@ export const useOAuth = () => { // Store expiration time if provided if (expires_in) { - const expiresAt = Date.now() + (expires_in * 1000); + const expiresAt = Date.now() + (expires_in); localStorage.setItem('tokenExpiresAt', expiresAt.toString()); }