From 989c3adacf155fa90bc123b7b55dcd38a20adf59 Mon Sep 17 00:00:00 2001 From: pkarw Date: Tue, 16 Jul 2019 10:15:29 +0200 Subject: [PATCH 1/2] Fix for #3151 and #3178 --- CHANGELOG.md | 1 + core/lib/sync/task.ts | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a7fa4b9fd..de0bf4c5c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed wrong meta description attribute by page overwrite - @przspa (#3091) - Fixed the `AddToCart` button behavior in case of synchronization errors - @pkarw (#3150) +- User token re-validation fixed to use proper HTTP codes - @pkarw (#3151, #3178) ### Changed - Renamed the `stock/check` to `stock/queueCheck` to better emphasize it's async nature; added `stock/check` which does exactly what name suggests - returning the true stock values - @pkarw (#3150) diff --git a/core/lib/sync/task.ts b/core/lib/sync/task.ts index ed765d56b0..02c5c599c5 100644 --- a/core/lib/sync/task.ts +++ b/core/lib/sync/task.ts @@ -73,9 +73,9 @@ function _internalExecute (resolve, reject, task: Task, currentToken, currentCar } }).then((jsonResponse) => { if (jsonResponse) { - if (parseInt(jsonResponse.code) !== 200) { - let resultString = jsonResponse.result ? toString(jsonResponse.result) : null - if (resultString && (resultString.indexOf(i18n.t('not authorized')) >= 0 || resultString.indexOf('not authorized')) >= 0 && currentToken !== null) { // the token is no longer valid, try to invalidate it + const responseCode = parseInt(jsonResponse.code) + if (responseCode !== 200) { + if (responseCode === 401 /** unauthorized */ && currentToken !== null) { // the token is no longer valid, try to invalidate it Logger.error('Invalid token - need to be revalidated' + currentToken + task.url + rootStore.state.userTokenInvalidateLock, 'sync')() if (isNaN(rootStore.state.userTokenInvalidateAttemptsCount) || isUndefined(rootStore.state.userTokenInvalidateAttemptsCount)) rootStore.state.userTokenInvalidateAttemptsCount = 0 if (isNaN(rootStore.state.userTokenInvalidateLock) || isUndefined(rootStore.state.userTokenInvalidateLock)) rootStore.state.userTokenInvalidateLock = 0 From b9e537e820b0b3fb061312d403bdbd7b32024276 Mon Sep 17 00:00:00 2001 From: pkarw Date: Tue, 16 Jul 2019 10:29:53 +0200 Subject: [PATCH 2/2] Fix for #3089 This is workaroundn for `cashonndelivery` being removed by `backend-payment-methods` module --- .../hooks/afterRegistration.ts | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/modules/payment-cash-on-delivery/hooks/afterRegistration.ts b/src/modules/payment-cash-on-delivery/hooks/afterRegistration.ts index 661f83bbe7..830ac9b831 100644 --- a/src/modules/payment-cash-on-delivery/hooks/afterRegistration.ts +++ b/src/modules/payment-cash-on-delivery/hooks/afterRegistration.ts @@ -9,20 +9,18 @@ export function afterRegistration ({ Vue, config, store, isServer }) { Vue.prototype.$bus.$emit('checkout-do-placeOrder', {}) } } - + // Update the methods + let paymentMethodConfig = { + 'title': 'Cash on delivery', + 'code': 'cashondelivery', + 'cost': 0, + 'costInclTax': 0, + 'default': true, + 'offline': true, + 'is_server_method': false + } + rootStore.dispatch('payment/addMethod', paymentMethodConfig) if (!isServer) { - // Update the methods - let paymentMethodConfig = { - 'title': 'Cash on delivery', - 'code': 'cashondelivery', - 'cost': 0, - 'costInclTax': 0, - 'default': true, - 'offline': true, - 'is_server_method': false - } - rootStore.dispatch('payment/addMethod', paymentMethodConfig) - Vue.prototype.$bus.$on('checkout-before-placeOrder', placeOrder) // Mount the info component when required.