Skip to content

Commit

Permalink
fix (token-validator): fix double check
Browse files Browse the repository at this point in the history
  • Loading branch information
HeitorMatt committed Oct 30, 2020
1 parent b203e86 commit 78e5f07
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/adonisjs/public/infra/token-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@ class TokenController {

set tokenChecked (newValue) {
this._tokenChecked = newValue
// console.log('new value: ' + this._tokenChecked)
}

get tokenChecked () {
// console.log(this._tokenChecked)
return this._tokenChecked
}

async checkToken () {
if (document.getElementById('harena-header')) {

if (TokenController.instance.tokenChecked) {
// elem.setAttribute('onclick', 'LoginTest.i.logout()')
// TokenController.instance.changeHeaderButtons('token valid')
} else {
if (!TokenController.instance.tokenChecked) {
const config = {
method: 'GET',
url: DCCCommonServer.managerAddressAPI + 'auth/check',
Expand All @@ -34,7 +29,6 @@ class TokenController {

await axios(config)
.then(function (endpointResponse) {
// console.log('check token');
TokenController.instance.changeHeaderButtons(endpointResponse.data)
})
.catch(function (error) {
Expand Down Expand Up @@ -97,14 +91,14 @@ class TokenController {
url: DCCCommonServer.managerAddressAPI + 'auth/check',
withCredentials: true
}
// console.log('=== check token request')
// console.log(DCCCommonServer.managerAddressAPI + 'auth/check')
await axios(config)
.then(function (endpointResponse) {
// console.log('=== check token redirect response')
// console.log(endpointResponse.data)
// endpointResponse.data === 'token valid' ? TokenController.instance.checkToken(true) : window.location.href = '/login'
endpointResponse.data.token === 'token valid' ? TokenController.instance.changeHeaderButtons(endpointResponse.data) : window.location.href = '/user'
if(endpointResponse.data.token === 'token valid'){
TokenController.instance.tokenChecked = true
TokenController.instance.changeHeaderButtons(endpointResponse.data)
} else{
window.location.href = '/user'
}
})
.catch(function (error) {
console.log('=== check redirect error')
Expand Down

0 comments on commit 78e5f07

Please sign in to comment.