From 8de42fc401c3a0ddc1572aa45027fb27ecbab4fd Mon Sep 17 00:00:00 2001 From: Matthew Hardern Date: Wed, 13 Apr 2022 14:45:24 +0100 Subject: [PATCH] f-loyalty@1.7.3 - auth token check (#1803) * auth token check * removing unused function * removing unused function --- .../components/pages/f-loyalty/CHANGELOG.md | 8 +++++ .../components/pages/f-loyalty/package.json | 2 +- .../f-loyalty/src/components/Loyalty.vue | 10 ++---- .../f-loyalty/src/store/loyalty.module.js | 36 +++++-------------- 4 files changed, 19 insertions(+), 37 deletions(-) diff --git a/packages/components/pages/f-loyalty/CHANGELOG.md b/packages/components/pages/f-loyalty/CHANGELOG.md index 6e22d8c318..35ea9846e2 100644 --- a/packages/components/pages/f-loyalty/CHANGELOG.md +++ b/packages/components/pages/f-loyalty/CHANGELOG.md @@ -4,6 +4,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +v1.7.3 +------------------------------ +*April 12, 2022* + +### Added +- Check for auth token before setting global user id + + v1.7.2 ------------------------------ *April 05, 2022* diff --git a/packages/components/pages/f-loyalty/package.json b/packages/components/pages/f-loyalty/package.json index e842d2631e..fa7566e1bb 100644 --- a/packages/components/pages/f-loyalty/package.json +++ b/packages/components/pages/f-loyalty/package.json @@ -1,7 +1,7 @@ { "name": "@justeat/f-loyalty", "description": "Fozzie Loyalty - provides a way for customers to collect loyalty stamps for restaurants", - "version": "1.7.2", + "version": "1.7.3", "main": "dist/f-loyalty.umd.min.js", "maxBundleSize": "101kB", "files": [ diff --git a/packages/components/pages/f-loyalty/src/components/Loyalty.vue b/packages/components/pages/f-loyalty/src/components/Loyalty.vue index 8adad7d0e2..68e16683fb 100644 --- a/packages/components/pages/f-loyalty/src/components/Loyalty.vue +++ b/packages/components/pages/f-loyalty/src/components/Loyalty.vue @@ -123,20 +123,14 @@ export default { async mounted () { await this.init({ brazeApiKey: this.brazeApiKey, - authToken: this.authToken, - logger: this.$log, - errorHandler: this.handleErrors + authToken: this.authToken }); }, methods: { ...mapActions(VUEX_MODULE_NAMESPACE_LOYALTY, { init: ACTION_INITIALISE_LOYALTY - }), - - handleErrors (error) { - this.$emit('onError', error); - } + }) } }; diff --git a/packages/components/pages/f-loyalty/src/store/loyalty.module.js b/packages/components/pages/f-loyalty/src/store/loyalty.module.js index bdd13ddffd..6f9cc46c5c 100644 --- a/packages/components/pages/f-loyalty/src/store/loyalty.module.js +++ b/packages/components/pages/f-loyalty/src/store/loyalty.module.js @@ -10,32 +10,10 @@ import { /** * @function resolveGlobalUserID * @param {string} authToken - auth token. - * @param logger - * @param errorHandler */ -const resolveGlobalUserID = (authToken, logger, errorHandler) => { - try { - const tokenData = jwtDecode(authToken); - return tokenData?.global_user_id; - } catch (error) { - logger.error( - 'Error Decoding JWT token', - error, - 'loyalty', - { - authToken, - exception: error.name, - exceptionMessage: error.message, - exceptionStackTrace: error.stack, - traceId: error.traceId || (error.response && error.response.data.traceId), - errorCode: error.errorCode - } - ); - // return null and emit error to allow component to emit on error event to - // prevent error being handled by general catch all error handler - errorHandler(error); - return null; - } +const resolveGlobalUserID = authToken => { + const tokenData = jwtDecode(authToken); + return tokenData?.global_user_id; }; export default { @@ -73,12 +51,14 @@ export default { commit(ACTION_SET_GLOBAL_USER_ID, resolveGlobalUserID(authToken, logger, errorHandler)); }, - [ACTION_INITIALISE_LOYALTY]: ({ commit, dispatch }, { - brazeApiKey, authToken, logger, errorHandler + [ACTION_INITIALISE_LOYALTY]: ({ commit, dispatch, getters }, { + brazeApiKey, authToken }) => { commit(MUTATION_SET_AUTH_TOKEN, authToken); commit(MUTATION_SET_BRAZE_KEY, brazeApiKey); - dispatch(ACTION_SET_GLOBAL_USER_ID, { authToken, logger, errorHandler }); + if (getters.isAuthenticated) { + dispatch(ACTION_SET_GLOBAL_USER_ID, { authToken }); + } } },